I have a template function in a shared library written in C++(the function is not called anywhere in the library, so it shouldn’t be generated, am i wrong?) [g++, Linux]
I try to use this template function in the application but compiler gives link error.I searched the function using objdump but I can not see the function in the .so
Is there a way to solve this problem?
Templates are hard to implement by compiler developers, and thus, most C++ compilers actually require you to put template code in header files, even complete class implementations (there are some exceptions and tricks to avoid this though).
For your case, all you need to do is move your function template to a header file (probably with other function templates) and import that when you need it.
Hope that helps.