254 Chapter 6
Shared Library Management Routines
The dlopen Shared Library Management Routines
Parameters
Return Values
If the referenced shared library was successfully closed, dlclose
returns 0. If the shared library could not be closed, or if handle does not
refer to an open shared library, dlclose returns a non-0 value. More
detailed diagnostic information is available through dlerror.
Description
dlclose disassociates a shared library previously opened by dlopen
from the current process. Once an shared library has been closed using
dlclose, dlsym no longer has access to its symbols. All shared
libraries loaded automatically as a result of invoking dlopen on the
referenced shared library [see dlopen(3C)] are also closed.
A successful invocation of dlclose does not guarantee that the shared
libraries associated with handle have actually been removed from the
address space of the process. shared libraries loaded by one invocation of
dlopen may also be loaded by another invocation of dlopen. The same
shared library may also be opened multiple times. An shared library is
not removed from the address space until all references to that shared
library through an explicit dlopen invocation have been closed and all
other shared libraries implicitly referencing that shared library have
also been closed. Once an shared library has been closed by dlclose,
referencing symbols contained in that shared library can cause
undefined behavior.
Example
The following example shows how to use dlclose to unload a shared
library:
void* handle;
int ret_value;
handle = dlopen(“./lib1.sl”, RTLD_GLOBAL | RTLD_LAZY);
Parm Definition
handle Value returned by a previous invocation of dlopen.