[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

dlsym Subroutine


Looks up the location of a symbol in a module that is loaded with dlsym.


#include <dlfcn.h>

void *dlsym(Data, Symbol);
void *Data;
const char *Symbol;


The dlsym subroutine looks up a named symbol exported from a module loaded by a previous call to the dlopen subroutine. Only exported symbols are found by dlsym. See the ld command to see how to export symbols from a module.

Data Specifies a value returned by a previous call to dlopen.
Symbol Specifies the name of a symbol exported from the referenced module. The form should be a NULL-terminated string.
C++ symbol names should be passed to dlsym in mangled form; dlsym does not perform any name demangling on behalf of the calling application.

A search for the named symbol is based upon breadth-first ordering of the module and its dependants. If the module was constructed using the -G or -brtl linker option, the module's dependants will include all modules named on the ld command line, in the original order. The dependants of a module that was not linked with the -G or -brtl linker option will be listed in an unspecified order.

Return Values

If the named symbol is found, its address is returned. If the named symbol is not found, NULL is returned and errno is set to 0. If Data or Symbol are invalid, NULL is returned and errno is set to EINVAL .

If the first definition found is an export of an imported symbol, this definition will satisfy the search. The address of the imported symbol is returned. If the first definition is a deferred import, the definition is ignored and the search continues.

If the named symbol refers to a BSS symbol (uninitialized data structure), the search continues until an initialized instance of the symbol is found or the module and all of its dependants have been searched . If an initialized instance is found, its address is returned; otherwise, the address of the first uninitialized instance is returned.

Error Codes

EINVAL If the Data parameter does not refer to a module opened by dlopen that is still loaded or if the Symbol parameter points to an invalid address, the dlsym subroutine returns NULL and errno is set to EINVAL.

Related Information

The dlclose (dlclose Subroutine) subroutine, dlerror (dlerror Subroutine) subroutine, dlopen (dlopen Subroutine) subroutine, load (load Subroutine) subroutine, loadbind (loadbind Subroutine) subroutine, loadquery (loadquery Subroutine)subroutine, unload subroutine.

The ld command.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]