Section: Linux Programmer's Manual (3)
Return to Main Contents
dlsym, dlvsym - obtain address of a symbol in a shared object or executable
void *dlsym(void *handle, const char *symbol);
void *dlvsym(void *handle, char *symbol, char *version);
Link with -ldl.
takes a "handle" of a dynamic loaded shared object returned by
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 by
when that object was loaded,
(The search performed by
is breadth first through the dependency tree of these shared objects.)
Since the value of the symbol could actually be NULL (so that a
NULL return from
need not indicate an error), the correct way to test for an error
is to call
to clear any old error conditions, then call
and then call
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 in
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 the
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
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).
feature test macro must be defined in order to obtain the
does the same as
but takes a version string as an additional argument.
these functions return the address associated with
On failure, they return NULL;
the cause of the error can be diagnosed using
is present in glibc 2.0 and later.
first appeared in glibc 2.1.
For an explanation of the terms used in this section, see
function is a GNU extension.
function is part of the dlopen API, derived from SunOS.
That system does not have
This page is part of release 4.15 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.
Time: 14:17:35 GMT, September 26, 2018