trying to understand undefined reference for dladdr

Brendan Miller catphive@catphive.net
Tue Aug 18 22:56:00 GMT 2009


I have some code like:

#include <dlfcn.h>
...
// function call in some code later.
dladdr(addr, &addrInfo);

That is compiled into a static library libmy_library.a

When I go to link the library into the program containing my main
routine I get this:
g++ -o program -rdynamic main.o  libmy_library.a
libmy_library.a(my_library.o): In function `SomeFunction(void*)':
/path/to/src/my_library.cpp:68: undefined reference to `dladdr'
collect2: ld returned 1 exit status

How can I get an undefined reference to something in glibc? I was
using other glibc functions fine, but dladdr seemed to throw it for a
loop. Maybe this has something to do with it being part of the family
of functions for dynamic loading libraries, and I'm trying to link it
from a static lib? I'm using lots of other glibc functions without
trouble. Are the dl* functions linked in some weird way?

Thanks,
Brendan



More information about the Libc-help mailing list