Link with a template class from a share object (c++)

N

nivas

Hi.

I want to build a program which dynamically loads from a shared object
a template class.
Thus:
1. I am creating the shared_object.cpp, shared_object.h which defines
the <template> class 2. Build with g++ -shared -fPIC shared_object.cpp
-o libshared_object.so 3. Inlcude the shared_object.h in the sources of
the program 4. build the program with -lshared_object

Unfortunately it complains about undefined reference to the class.
Any help

Thanks
Nik
 
O

ondra.holub

I think you have definition of template methods in .cc (.cpp) file, not
in header. When you want to use templates, you have to write
definitions of template methods (functions) into header.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top