Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

1,225 views
Skip to first unread message

Cyan

unread,
Aug 13, 2002, 9:31:29 PM8/13/02
to
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

mlw

unread,
Aug 13, 2002, 10:51:55 PM8/13/02
to
Cyan wrote:
>
> 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;

}

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;

Cyan

unread,
Aug 14, 2002, 7:57:08 AM8/14/02
to
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

mlw

unread,
Aug 14, 2002, 8:44:28 AM8/14/02
to
Cyan wrote:
>
> 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?

Pierre Sarrazin

unread,
Aug 14, 2002, 2:25:52 PM8/14/02
to
Dixit Cyan (2002-08-14 01:31 GMT) <3D59B2F1...@hotmail.com>:

> 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.


[...]


> ../../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/

0 new messages