NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ATTRIBUTES |STANDARDS |HISTORY |NOTES |EXAMPLES |SEE ALSO |COLOPHON | |
dlsym(3) Library Functions Manualdlsym(3)dlsym, dlvsym - obtain address of a symbol in a shared object or executable
Dynamic linking library (libdl,-ldl)
#include <dlfcn.h>void *dlsym(void *restricthandle, const char *restrictsymbol);#define _GNU_SOURCE#include <dlfcn.h>void *dlvsym(void *restricthandle, const char *restrictsymbol,const char *restrictversion);
The functiondlsym() takes a "handle" of a dynamic loaded shared object returned bydlopen(3) along with a null-terminated symbol name, and returns the address where that symbol is loaded into memory. If the symbol is not found, in the specified object or any of the shared objects that were automatically loaded bydlopen(3) when that object was loaded,dlsym() returns NULL. (The search performed bydlsym() is breadth first through the dependency tree of these shared objects.) In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return fromdlsym() need not indicate an error. The correct way to distinguish an error from a symbol whose value is NULL is to calldlerror(3) to clear any old error conditions, then calldlsym(), and then calldlerror(3) again, saving its return value into a variable, and check whether this saved value is not NULL. There are two special pseudo-handles that may be specified inhandle:RTLD_DEFAULT Find the first occurrence of the desired symbol using the default shared object search order. The search will include global symbols in the executable and its dependencies, as well as symbols in shared objects that were dynamically loaded with theRTLD_GLOBALflag.RTLD_NEXT Find the next occurrence of the desired symbol in the search order after the current object. This allows one to provide a wrapper around a function in another shared object, so that, for example, the definition of a function in a preloaded shared object (seeLD_PRELOADinld.so(8)) can find and invoke the "real" function provided in another shared object (or for that matter, the "next" definition of the function in cases where there are multiple layers of preloading). The_GNU_SOURCEfeature test macro must be defined in order to obtain the definitions ofRTLD_DEFAULTandRTLD_NEXTfrom<dlfcn.h>. The functiondlvsym() does the same asdlsym() but takes a version string as an additional argument.
On success, these functions return the address associated withsymbol. On failure, they return NULL; the error can be diagnosed usingdlerror(3).
For an explanation of the terms used in this section, seeattributes(7). ┌──────────────────────────────────────┬───────────────┬─────────┐ │Interface│Attribute│Value│ ├──────────────────────────────────────┼───────────────┼─────────┤ │dlsym(),dlvsym() │ Thread safety │ MT-Safe │ └──────────────────────────────────────┴───────────────┴─────────┘
dlsym() POSIX.1-2008.dlvsym() GNU.
dlsym() glibc 2.0. POSIX.1-2001.dlvsym() glibc 2.1.
There are several scenarios when the address of a global symbol is NULL. For example, a symbol can be placed at zero address by the linker, via a linker script or with--defsym command-line option. Undefined weak symbols also have NULL value. Finally, the symbol value may be the result of a GNU indirect function (IFUNC) resolver function that returns NULL as the resolved value. In the latter case,dlsym() also returns NULL without error. However, in the former two cases, the behavior of GNU dynamic linker is inconsistent: relocation processing succeeds and the symbol can be observed to have NULL value, butdlsym() fails anddlerror() indicates a lookup error.History Thedlsym() function is part of the dlopen API, derived from SunOS. That system does not havedlvsym().
Seedlopen(3).
dl_iterate_phdr(3),dladdr(3),dlerror(3),dlinfo(3),dlopen(3),ld.so(8)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-05-17dlsym(3)Pages that refer to this page:dladdr(3), dlerror(3), dlinfo(3), dlopen(3), rtld-audit(7)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |