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

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

  1. nivas

    nivas Guest

    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
    nivas, Nov 21, 2006
    #1
    1. Advertising

  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
    #2
    1. Advertising

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.
Similar Threads
  1. christopher diggins
    Replies:
    16
    Views:
    745
    Pete Becker
    May 4, 2005
  2. Replies:
    1
    Views:
    328
    John Harrison
    Feb 21, 2007
  3. A L
    Replies:
    1
    Views:
    510
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,318
    Saraswati lakki
    Jan 6, 2012
  5. Jack
    Replies:
    2
    Views:
    212
Loading...

Share This Page