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

Discussion in 'C++' started by nivas, Nov 21, 2006.

  1. nivas

    nivas Guest


    I want to build a program which dynamically loads from a shared object
    a template class.
    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 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

    nivas, Nov 21, 2006
    1. Advertisements

  2. nivas

    ondra.holub Guest

    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.
    ondra.holub, Nov 21, 2006
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.