Section (3) dlsym
dlsym, dlvsym — obtain address of a symbol in a shared object or executable
|const char *symbol
#define _GNU_SOURCE #include <dlfcn.h>
dlsym() takes a
handle of a dynamic loaded shared object returned by
dlopen(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 by dlopen(3) when that object
NULL. (The search performed by
dlsym() 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 from
dlsym() need not indicate an error. The
correct way to distinguish an error from a symbol whose value
is NULL is to call dlerror(3) to clear any old
error conditions, then call
dlsym(), and then call dlerror(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
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 (see
LD_PRELOADin ld.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).
_GNU_SOURCE feature test
macro must be defined in order to obtain the definitions of
the same as
dlsym() but takes a
version string as an additional argument.
On success, these functions return the address associated
failure, they return NULL; the cause of the error can be
diagnosed using dlerror(3).
For an explanation of the terms used in this section, see attributes(7).
The value of a symbol returned by
dlsym() will never be NULL if the shared
object is the result of normal compilation, since a global
symbol is never placed at the NULL address. There are
nevertheless cases where a lookup using
dlsym() may return NULL as the value of a
symbol. For example, the symbol value may be the result of a
GNU indirect function (IFUNC) resolver function that returns
NULL as the resolved value.
This page is part of release 5.04 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright 1995 Yggdrasil Computing, Incorporated.
and Copyright 2003, 2015 Michael Kerrisk <mtk.manpagesgmail.com>
This is free documentation; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The GNU General Public License_zsingle_quotesz_s references to object code
and executables are to be interpreted as the output of any
document formatting or typesetting system, including
intermediate and printed output.
This manual is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this manual; if not, see