Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

dlsym - get the address of a symbol from a dlopen() object

&pagelevel(3)&pagelevel

Syntax


#include <dlfcn.h>
void *dlsym(void *handle, const char *name);


The function __dlsym_ascii() with the same parameters must be used for the call in an ASCII environment.

Description

dlsym() allows a process to obtain the address of a symbol defined within an object made accessible through a dlopen() call.

handle determines the search strategy. For handle the following entries are possible:

  • The value that is returned by a dlopen() call and which has not been released since then by a dlclose() call.
  • RTLD_DEFAULT
    All objects are searched in the chronological sequence of their loading.
  • RTLD_NEXT
    This only searches objects that were loaded after the object in which the dlsym() call was performed.
  • RTLD_SELF
    The object from which the call dlsym() is placed is searched first. All objects loaded afterwards are searched next.

name is the name of the symbol as character string.

Return value

If handle does not refer to a valid object, or if the named symbol cannot be found within any of the objects associated with handle, dlsym() will return NULL.

Note, that capitalization and the replacement of ’_’ through ’$’ are defined during the compiling of the objects (with corresponding options of the cc command).

The errno variable is not set. An error message (diagnostic information) will be available through dlerror().

Example

The following example shows how one can use dlopen() and dlsym() to access either function or data objects. For simplicity, error checking has been omitted.

void    *handle; 
int     *iptr, (*fptr)(int);

/* Opening the appropriate object*/ 
handle = dlopen("/usr/home/me/libfoo.so.1",RTLD_LAZY);

/* Searching the address of functions and data objects*/ 
fptr = (int (*)(int))dlsym(handle, "my_function"); 
iptr = (int *)dlsym(handle, "my_object");

/* Calling the function and handing over the integer value as a parameter*/ 
(*fptr)(*iptr);

See also

dlclose(), dlerror(), dlopen()