dlopen() - open shared object
#include <dlfcn.h>
void *dlopen(const char *file, int mode)
The dlopen(3) call opens a shared object, usually a shared library, and makes it available to the calling process. The file is the pathname to the object file, and the mode describes how the call will operate on the file. A successful call returns a handle; this is an opaque object and shouldn't be interpreted. It can be used in calls to dlsym(3) and dlclose(3).
The file is the pathname to the object. If file is 0, dlopen(3) provides a handle for a global symbol object. The global symbol object gives access to all global symbols; the symbols included are those in the original program image file, plus those loaded at startup time, plus any symbols loaded as a result of a dlopen(3) call that used the RTLD_GLOBAL flag. The contents of the global symbol object can change dynamically as a result of subsequent dlopen(3) calls.
Only a single copy of an object file is loaded into the address space, even if the object is referred to multiple times, and even if different pathnames are used to refer to the same file.
The mode controls processing of the relocations of the symbols in the file, and the scope of visibility of those symbols. For example, an object may contain references to symbols with addresses that aren't known until the object is loaded; those references must be relocated before the process can access the symbols. The posible values for mode are:
Global symbols may also need to be relocated. One of the following values for mode should be OR'ed with the other value; if neither is specified, it defaults to RTLD_LOCAL.
Symbols may be used in relocation activies; calls to dlopen(3) may introduce symbols that duplicate existing symbols. A symbol reference is resolved in either load order or in dependency order, matching the symbol that occurs first in that order.
Load order is exactly as it sounds: symbols in the main program file (and its dependent files) take precedence over symbols loaded using dlopen(3). Load order always starts with the main image file.
Dependency order starts with a given object file (not necessarily the main program file) and orders breadth first, all of the objuect's dependencies, then those dependencies, iterating until all dependencies are satisfied. Most dlsym(3) searches are done in dependency order; the exception is searches on the global symbol object loaded with dlopen(0,mode), which uses load order.
The dlopen(3) call returns a handle on success, or NULL if an error occured. It's an error if the file cannot be found, if it can't be loaded or the symbols processed. Use dlerror(3) to get more information.
ld(1)
dlclose(3)
dlerror(3)
dlsym(3)