C++ classes in shared objects give undefined symbol :(

C++ classes in shared objects give undefined symbol :(

Post by Cyan » Thu, 15 Aug 2002 10:31:29



Hi,
  Classes which I define in a shared library for dynamic loading always
seem to end up with lots of their symbols being undefined when I attempt
to use them / do "nm" on them.

  I think that all the missing symbols are from the abstract base class
of the one being defined in the library.

  Any ideas why this sort of thing happens?

Thanks,
Cyan

dlopen fails with:
undefined symbol: __ti6Finder

Automake said:

/bin/sh ../../../libtool --mode=compile --tag=CXX c++ -DHAVE_CONFIG_H
-I. -I. -I../../.. -I/usr/include/kde -I/usr/include/qt
-I/usr/X11R6/include   -D_REENTRANT  -O2 -O0 -g3 -Wall -fno-exceptions
-fno-check-new  -c fpsmgnlz1.cpp
c++ -DHAVE_CONFIG_H -I. -I. -I../../.. -I/usr/include/kde
-I/usr/include/qt -I/usr/X11R6/include -D_REENTRANT -O2 -O0 -g3 -Wall
-fno-exceptions -fno-check-new -Wp,-MD,.deps/fpsmgnlz1.pp -c
fpsmgnlz1.cpp  -fPIC -DPIC -o .libs/fpsmgnlz1.o
In file included from fpsmgnlz1.h:20,
                  from fpsmgnlz1.cpp:26:
../../finder.h:126: warning: `class Finder' has virtual functions but
non-virtual destructor
In file included from fpsmgnlz1.cpp:26:
fpsmgnlz1.h:57: warning: `class PupilSpotMarginalize1' has virtual
functions but non-virtual destructor
/bin/sh ../../../libtool --mode=link --tag=CXX c++  -O2 -O0 -g3 -Wall
-fno-exceptions -fno-check-new   -o libfpsmgnlz1.la -rpath
/usr/local/kde/lib -version-info 0:0:0 fpsmgnlz1.lo -limageutil
rm -fr  .libs/libfpsmgnlz1.la .libs/libfpsmgnlz1.lai
.libs/libfpsmgnlz1.so .libs/libfpsmgnlz1.so.0 .libs/libfpsmgnlz1.so.0.0.0
c++ -shared -nostdlib /usr/lib/crti.o
/usr/lib/gcc-lib/i386-linux/2.95.4/crtbeginS.o  .libs/fpsmgnlz1.o
-limageutil -lqt -L/usr/lib/gcc-lib/i386-linux/2.95.4 -lstdc++ -lm -lc
-lgcc /usr/lib/gcc-lib/i386-linux/2.95.4/crtendS.o /usr/lib/crtn.o   -O2
-O0 -g3 -Wall -fno-exceptions -fno-check-new -Wl,-soname
-Wl,libfpsmgnlz1.so.0 -o .libs/libfpsmgnlz1.so.0.0.0

 
 
 

C++ classes in shared objects give undefined symbol :(

Post by mlw » Thu, 15 Aug 2002 11:51:55



> Hi,
>   Classes which I define in a shared library for dynamic loading always
> seem to end up with lots of their symbols being undefined when I attempt
> to use them / do "nm" on them.

>   I think that all the missing symbols are from the abstract base class
> of the one being defined in the library.

>   Any ideas why this sort of thing happens?

How are you loading it into your program? Try not to use RTLD_GLOBAL because it
forces symbols in your .SO file to be global within your app.

This is my dynamic loader:

Boolean MPlugin::openlib(char *name)
{
        m_dll = dlopen(name, RTLD_NOW);

        if(!m_dll)
        {
                char buffer[PATH_MAX];
                mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
dlerror());
                getcwd(buffer, sizeof(buffer));
                sprintf(&buffer[strlen(buffer)], "/%s", name);

                m_dll = dlopen(buffer, RTLD_NOW);
        }

        if(!m_dll)
                mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
dlerror());

        return m_dll ? TRUE : FALSE;

Quote:}

Here is how I get function pointers:
void *MPlugin::getpfn(char *name)
{
        void * pfn = dlsym(m_dll, name);
        if(!pfn)
                mferr.mfprintf("MPlugin dlsym Warning: %s\n", dlerror());
        return pfn;
Quote:}

> Thanks,
> Cyan

> dlopen fails with:
> undefined symbol: __ti6Finder

> Automake said:

> /bin/sh ../../../libtool --mode=compile --tag=CXX c++ -DHAVE_CONFIG_H
> -I. -I. -I../../.. -I/usr/include/kde -I/usr/include/qt
> -I/usr/X11R6/include   -D_REENTRANT  -O2 -O0 -g3 -Wall -fno-exceptions
> -fno-check-new  -c fpsmgnlz1.cpp
> c++ -DHAVE_CONFIG_H -I. -I. -I../../.. -I/usr/include/kde
> -I/usr/include/qt -I/usr/X11R6/include -D_REENTRANT -O2 -O0 -g3 -Wall
> -fno-exceptions -fno-check-new -Wp,-MD,.deps/fpsmgnlz1.pp -c
> fpsmgnlz1.cpp  -fPIC -DPIC -o .libs/fpsmgnlz1.o
> In file included from fpsmgnlz1.h:20,
>                   from fpsmgnlz1.cpp:26:
> ../../finder.h:126: warning: `class Finder' has virtual functions but
> non-virtual destructor
> In file included from fpsmgnlz1.cpp:26:
> fpsmgnlz1.h:57: warning: `class PupilSpotMarginalize1' has virtual
> functions but non-virtual destructor
> /bin/sh ../../../libtool --mode=link --tag=CXX c++  -O2 -O0 -g3 -Wall
> -fno-exceptions -fno-check-new   -o libfpsmgnlz1.la -rpath
> /usr/local/kde/lib -version-info 0:0:0 fpsmgnlz1.lo -limageutil
> rm -fr  .libs/libfpsmgnlz1.la .libs/libfpsmgnlz1.lai
> .libs/libfpsmgnlz1.so .libs/libfpsmgnlz1.so.0 .libs/libfpsmgnlz1.so.0.0.0
> c++ -shared -nostdlib /usr/lib/crti.o
> /usr/lib/gcc-lib/i386-linux/2.95.4/crtbeginS.o  .libs/fpsmgnlz1.o
> -limageutil -lqt -L/usr/lib/gcc-lib/i386-linux/2.95.4 -lstdc++ -lm -lc
> -lgcc /usr/lib/gcc-lib/i386-linux/2.95.4/crtendS.o /usr/lib/crtn.o   -O2
> -O0 -g3 -Wall -fno-exceptions -fno-check-new -Wl,-soname
> -Wl,libfpsmgnlz1.so.0 -o .libs/libfpsmgnlz1.so.0.0.0


 
 
 

C++ classes in shared objects give undefined symbol :(

Post by Cyan » Thu, 15 Aug 2002 20:57:08


Hi,
  I am loading my .so in exactly the same way you are, but dlopen fails
with undefined symbols :(. Do you have classes defined in your shared
object? It seems that only names first declared in the abstract base
class (from a shared header file) (and later defined in the class in the
.so) get missing symbols for me.

Cyan


> How are you loading it into your program? Try not to use RTLD_GLOBAL because it
> forces symbols in your .SO file to be global within your app.

> This is my dynamic loader:

> Boolean MPlugin::openlib(char *name)
> {
>         m_dll = dlopen(name, RTLD_NOW);

>         if(!m_dll)
>         {
>                 char buffer[PATH_MAX];
>                 mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
> dlerror());
>                 getcwd(buffer, sizeof(buffer));
>                 sprintf(&buffer[strlen(buffer)], "/%s", name);

>                 m_dll = dlopen(buffer, RTLD_NOW);
>         }

>         if(!m_dll)
>                 mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
> dlerror());

>         return m_dll ? TRUE : FALSE;

> }

> Here is how I get function pointers:
> void *MPlugin::getpfn(char *name)
> {
>         void * pfn = dlsym(m_dll, name);
>         if(!pfn)
>                 mferr.mfprintf("MPlugin dlsym Warning: %s\n", dlerror());
>         return pfn;
> }

>>Thanks,
>>Cyan

>>dlopen fails with:
>>undefined symbol: __ti6Finder

>>Automake said:

>>/bin/sh ../../../libtool --mode=compile --tag=CXX c++ -DHAVE_CONFIG_H
>>-I. -I. -I../../.. -I/usr/include/kde -I/usr/include/qt
>>-I/usr/X11R6/include   -D_REENTRANT  -O2 -O0 -g3 -Wall -fno-exceptions
>>-fno-check-new  -c fpsmgnlz1.cpp
>>c++ -DHAVE_CONFIG_H -I. -I. -I../../.. -I/usr/include/kde
>>-I/usr/include/qt -I/usr/X11R6/include -D_REENTRANT -O2 -O0 -g3 -Wall
>>-fno-exceptions -fno-check-new -Wp,-MD,.deps/fpsmgnlz1.pp -c
>>fpsmgnlz1.cpp  -fPIC -DPIC -o .libs/fpsmgnlz1.o
>>In file included from fpsmgnlz1.h:20,
>>                  from fpsmgnlz1.cpp:26:
>>../../finder.h:126: warning: `class Finder' has virtual functions but
>>non-virtual destructor
>>In file included from fpsmgnlz1.cpp:26:
>>fpsmgnlz1.h:57: warning: `class PupilSpotMarginalize1' has virtual
>>functions but non-virtual destructor
>>/bin/sh ../../../libtool --mode=link --tag=CXX c++  -O2 -O0 -g3 -Wall
>>-fno-exceptions -fno-check-new   -o libfpsmgnlz1.la -rpath
>>/usr/local/kde/lib -version-info 0:0:0 fpsmgnlz1.lo -limageutil
>>rm -fr  .libs/libfpsmgnlz1.la .libs/libfpsmgnlz1.lai
>>.libs/libfpsmgnlz1.so .libs/libfpsmgnlz1.so.0 .libs/libfpsmgnlz1.so.0.0.0
>>c++ -shared -nostdlib /usr/lib/crti.o
>>/usr/lib/gcc-lib/i386-linux/2.95.4/crtbeginS.o  .libs/fpsmgnlz1.o
>>-limageutil -lqt -L/usr/lib/gcc-lib/i386-linux/2.95.4 -lstdc++ -lm -lc
>>-lgcc /usr/lib/gcc-lib/i386-linux/2.95.4/crtendS.o /usr/lib/crtn.o   -O2
>>-O0 -g3 -Wall -fno-exceptions -fno-check-new -Wl,-soname
>>-Wl,libfpsmgnlz1.so.0 -o .libs/libfpsmgnlz1.so.0.0.0

 
 
 

C++ classes in shared objects give undefined symbol :(

Post by mlw » Thu, 15 Aug 2002 21:44:28



> Hi,
>   I am loading my .so in exactly the same way you are, but dlopen fails
> with undefined symbols :(. Do you have classes defined in your shared
> object? It seems that only names first declared in the abstract base
> class (from a shared header file) (and later defined in the class in the
> .so) get missing symbols for me.

Hmm, how are you compiling your shared object?

> Cyan


> > How are you loading it into your program? Try not to use RTLD_GLOBAL because it
> > forces symbols in your .SO file to be global within your app.

> > This is my dynamic loader:

> > Boolean MPlugin::openlib(char *name)
> > {
> >         m_dll = dlopen(name, RTLD_NOW);

> >         if(!m_dll)
> >         {
> >                 char buffer[PATH_MAX];
> >                 mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
> > dlerror());
> >                 getcwd(buffer, sizeof(buffer));
> >                 sprintf(&buffer[strlen(buffer)], "/%s", name);

> >                 m_dll = dlopen(buffer, RTLD_NOW);
> >         }

> >         if(!m_dll)
> >                 mferr.mfprintf("MPlugin dlopen Error: %s %s\n", name,
> > dlerror());

> >         return m_dll ? TRUE : FALSE;

> > }

> > Here is how I get function pointers:
> > void *MPlugin::getpfn(char *name)
> > {
> >         void * pfn = dlsym(m_dll, name);
> >         if(!pfn)
> >                 mferr.mfprintf("MPlugin dlsym Warning: %s\n", dlerror());
> >         return pfn;
> > }

> >>Thanks,
> >>Cyan

> >>dlopen fails with:
> >>undefined symbol: __ti6Finder

> >>Automake said:

> >>/bin/sh ../../../libtool --mode=compile --tag=CXX c++ -DHAVE_CONFIG_H
> >>-I. -I. -I../../.. -I/usr/include/kde -I/usr/include/qt
> >>-I/usr/X11R6/include   -D_REENTRANT  -O2 -O0 -g3 -Wall -fno-exceptions
> >>-fno-check-new  -c fpsmgnlz1.cpp
> >>c++ -DHAVE_CONFIG_H -I. -I. -I../../.. -I/usr/include/kde
> >>-I/usr/include/qt -I/usr/X11R6/include -D_REENTRANT -O2 -O0 -g3 -Wall
> >>-fno-exceptions -fno-check-new -Wp,-MD,.deps/fpsmgnlz1.pp -c
> >>fpsmgnlz1.cpp  -fPIC -DPIC -o .libs/fpsmgnlz1.o
> >>In file included from fpsmgnlz1.h:20,
> >>                  from fpsmgnlz1.cpp:26:
> >>../../finder.h:126: warning: `class Finder' has virtual functions but
> >>non-virtual destructor
> >>In file included from fpsmgnlz1.cpp:26:
> >>fpsmgnlz1.h:57: warning: `class PupilSpotMarginalize1' has virtual
> >>functions but non-virtual destructor
> >>/bin/sh ../../../libtool --mode=link --tag=CXX c++  -O2 -O0 -g3 -Wall
> >>-fno-exceptions -fno-check-new   -o libfpsmgnlz1.la -rpath
> >>/usr/local/kde/lib -version-info 0:0:0 fpsmgnlz1.lo -limageutil
> >>rm -fr  .libs/libfpsmgnlz1.la .libs/libfpsmgnlz1.lai
> >>.libs/libfpsmgnlz1.so .libs/libfpsmgnlz1.so.0 .libs/libfpsmgnlz1.so.0.0.0
> >>c++ -shared -nostdlib /usr/lib/crti.o
> >>/usr/lib/gcc-lib/i386-linux/2.95.4/crtbeginS.o  .libs/fpsmgnlz1.o
> >>-limageutil -lqt -L/usr/lib/gcc-lib/i386-linux/2.95.4 -lstdc++ -lm -lc
> >>-lgcc /usr/lib/gcc-lib/i386-linux/2.95.4/crtendS.o /usr/lib/crtn.o   -O2
> >>-O0 -g3 -Wall -fno-exceptions -fno-check-new -Wl,-soname
> >>-Wl,libfpsmgnlz1.so.0 -o .libs/libfpsmgnlz1.so.0.0.0

 
 
 

C++ classes in shared objects give undefined symbol :(

Post by Pierre Sarraz » Fri, 16 Aug 2002 03:25:52



Quote:>   Classes which I define in a shared library for dynamic loading always
> seem to end up with lots of their symbols being undefined when I attempt
> to use them / do "nm" on them.

>   I think that all the missing symbols are from the abstract base class
> of the one being defined in the library.

>   Any ideas why this sort of thing happens?

> Thanks,
> Cyan

> dlopen fails with:
> undefined symbol: __ti6Finder

It might be useful to check if your shared library is complete by
trying to link it with a stub program:

    echo 'int main() { return 0; }' > progtemp.cpp
    g++ progtemp.cpp libfpsmgnlz1.so

This will display all undefined references, while dlerror() only
reports the first one.

This sort of verification can be integrated in a makefile's 'check'
target.

        [...]

Quote:> ../../finder.h:126: warning: `class Finder' has virtual functions but
> non-virtual destructor
> In file included from fpsmgnlz1.cpp:26:
> fpsmgnlz1.h:57: warning: `class PupilSpotMarginalize1' has virtual
> functions but non-virtual destructor

It wouldn't hurt to fix those warnings.

--
Pierre Sarrazin <sarrazip at sympatico dot ca> http://sarrazip.com/en/

 
 
 

1. Problem compiling C++ shared library. Undefined symbol ___unwind_function.

I installed the Tclodbc 1.4 package by compiling from source
on a FreeBSD 2.2.8 system.  When compiled using the original
Makefile, a compiler warning was displayed saying that the
the option -fhandle-exceptions was needed and the compile
failed. The C++ source uses the "try" feature which I guessed
had something to do with this warning about exception handling.
I recompiled with this additional compiler option and was then
able to complete the build and installation of shared library
libTclodbc14.so without further errors.

Now when I attempt to load the shared library as a Tcl package
it fails as in this example:

tcl>package require Tclodbc
Error: couldn't load file "/usr/local/lib/libTclodbc14.so":
 Undefined symbol
"___unwind_function" in tcl:/usr/local/lib/libTclodbc14.so

My first guess was that a library had been omitted from the
link stage but I was unable to find any reference to name
"unwind_function" in any of the program source nor in any
system shared libraries.

Can anyone suggest what I need to do to compile this correctly
with GNU C++?

Thanks in advance.

2. cracker dictionaries

3. ld: Undefined symbol _cos _sin ?? :(

4. NT vs Unix

5. creating new shared object from existing shared objects ??

6. Resolution in X

7. Concurrent object class in C++ under UN*X

8. Sun console cable on a Sun Blade

9. installing Apache, PHP and MySQL gives undefined symbol

10. PGP for linux gives undefined symbol?

11. undefined symbol ::__vtbl with Sun WorkShop 6 update 1 C++ Compiler (5.2)

12. ld hiding class objects in a shared library

13. unresolved symbols for C++ class constructor & deconstrutor