cc ... -ldl ... #include <dlfcn.h> typedef struct { const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; } Dl_info; int dladdr(void *address, Dlinfo *dlip); |
This function implements the System V dynamic linking routines.
The dladdr() function is the inverse of the dlsym() function. If the given address is successfully located inside a module, dladdr() returns nonzero, otherwise 0. On a successful return, the fields of dlip are filled in as follows:
the pathname of the module
the base address of the module
the name of the highest addressed symbol whose address precedes the given address
the address of that symbol
Shared objects must be linked using the -shared option to the linker ld(1). The linker flag -rpath may be used to add a directory to the default search path for shared objects and shared libraries. The linker flag -E or the C compiler flag -rdynamic should be used to cause the application to export its symbols to the shared objects.