views:

464

answers:

2
+4  Q: 

gcc linker issue

I am trying to make a library that wraps libpurple (you shouldn't need to know anything about libpurple to help here). Libpurple in turn loads "plugins" which are just .so's accessed via something like dlopen. Those plugins in turn call back to functions in libpurple.

I can build my library just fine, but when it calls the appropriate libpurple init function, and libpurple tries to load a plugin, I get an error like the following:

symbol lookup error: /usr/local/lib/purple-2/autoaccept.so: undefined symbol: purple_user_dir

purple_user_dir is a function defined in libpurple. When I build a program (not a library) that links to libpurple there are no problems. I have tried using -export-dynamic and that did not seem to help. Here is my build command:

gcc -export-dynamic -I/usr/local/include/libpurple -I/usr/include/python2.5 -DH\
AVE_CONFIG_H -I. -DSTANDALONE -DBR_PTHREADS=0 -DDATADIR=\"/usr/local/share\" -D\
LIBDIR=\"/usr/local/lib/purple-2/\" -DLOCALEDIR=\"/usr/local/share/locale\" -DS\
YSCONFDIR=\"/usr/local/etc\" -Wall  -Waggregate-return -Wcast-align -Wdeclarati\
on-after-statement -Wendif-labels -Werror-implicit-function-declaration -Wextra\
 -Wno-sign-compare -Wno-unused-parameter -Winit-self -Wmissing-declarations -Wm\
issing-noreturn -Wmissing-prototypes -Wpointer-arith -Wundef -Wp,-D_FORTIFY_SOU\
RCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include   -I/usr/inc\
lude/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/gl\
ib-2.0/include   -I/usr/include/libxml2   -g -g -O2 -c -o spurple.o spurple.c

gcc -shared -g -O2 -Wl,--export-dynamic -pthread 
../../libpurple/.libs/libpurple.so -o spurple.so spurple.o 
-Wl,--export-dynamic  /usr/local/lib/libpurple.so 
-ldbus-glib-1 -ldbus-1 /usr/lib/libgobject-2.0.so /usr/lib/libgmodule-2.0.so 
-ldl /usr/lib/libgthread-2.0.so -lrt /usr/lib/libglib-2.0.so 
/usr/lib/libxml2.so -lm -lpython2.5 -lutil -lpthread -lnsl -lresolv

Thanks.

+1  A: 

I would try to use the ldd and nm unix commands to look for the symbols in the wrapper and wrapped libraries.

Yuval F
From using nm, it looks like purple_user_dir is defined in libpurple.so but not in the wrapper (spurple.so). Is that how it should be? Some other symbols from libpurple are defined in spurple.so, it looks like functions that I happened to call, but not purple_user_dir for example.
So perhaps you need to 'redefine' it in spurple.so?
leppie
Is there a way to make spurple.so automatically pull in all the symbols from libpurple, without me having to 'redefine' each one of them?
+1  A: 

Just a shot in the dark, but do you have a different LD_LIBRARY_PATH environment variable when you build the app than when you run it?

Tim Howland