dlopen(3) — Subroutines
NAME
dlopen, dlsym, dlclose, dlerror − interface to dynamic library loader
SYNOPSIS
#include <stdio.h>
#include <dlfcn.h>
void ∗dlopen(pathname, mode)
char ∗pathname;
int mode;
void ∗dlsym(handle, name)
void ∗handle;
char ∗name;
void dlclose(handle)
void ∗handle;
char ∗dlerror(void)
DESCRIPTION
The dlopen function provides an interface to the dynamic library loader to allow shared libraries to be loaded and called at runtime. The dlopen function attempts to load pathname, in the address space of the process, resolving symbols as appropriate. Any libraries that pathname depends upon are also loaded.
If pathname includes a /, dlopen will attempt to open it as specified. Otherwise, dlopen will attempt to locate pathname using shared library search directories in the order specified below (see loader(5) for more details on shared library search directories):
1.The current directory
2.The program’s rpath directories
3.LD_LIBRARY_PATH directories
4.Default shared library directories
If mode is RTLD_LAZY, then the runtime loader does symbol resolution only as needed. Typically, this means that the first call to a function in the newly loaded library will cause the resolution of the address of that function to occur. If mode is RTLD_NOW, then the runtime loader must do all symbol binding during the dlopen call. The dlopen function returns a handle that is used by dlsym or dlclose call. If there is an error, a NULL pointer is returned.
If a NULL pathname is specified, dlopen returns a handle for the main executable, which allows access to dynamic symbols in the running program.
The dlsym function returns the address of the symbol name found in the shared library corresponding to handle. If the symbol is not found, a NULL pointer is returned.
The dlclose function deallocates the address space for the library corresponding to handle. If any user function continues to call a symbol resolved in the address space of a library that has been since been deallocated by dlclose, the results are undefined.
The dlerror function returns a string describing the last error that occurred from a call to dlopen, dlclose or dlsym.