This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F2809: Template Function isn't Included in Static Library

Part Number: TMS320F2809


Tool/software: TI C/C++ Compiler

Hi,

I'm having a problem with a situation where I have an executable project depend on a static library project which uses (internally) a fully instantiated template type and calls one of its member functions.

When linking with the executable which uses a function from the library that does the template member call, the link fails with unresolved symbols unless I instantiate the template in the executable project as well (in which case it seems that the linker edits the executable object file at link time to include the required template member definition).

I've narrowed it down to template type member functions which aren't defined in the type's body and reproduced the problem with every compiler version since 16.9.0 up to 18.1.1

A minimal test case is attached. I hope this isn't intended behaviour because including internal library files is an ugly hack and it messes up my build.

Thanks,

Ane.

ti-template.zip

  • You have encountered a known problem with template instantiation in the C2000 compiler.  (BTW, the C5000 compiler has the same problem.)  Please see the article C++ Template Instantiation Issues for an in-depth explanation of the problem, and four workarounds for it.

    Briefly, the C2000 compiler uses a method called late template instantiation.  It works well for common cases.  But when templates needs to be instantiated in library code, problems can occur.  The solution in your case is to use what the article calls the "first workaround", which is to inline all the functions in the template definitions file template.hpp.  If that solution is impractical, the article details 3 other workarounds.  One of them is likely to work.

    Note that all the other TI compilers support EABI.  Under EABI, templates are instantiated with a different method.  This method avoids all these problems.  

    Thanks and regards,

    -George