User's Manual
Table 29 Parameters
DefinitionParameter
Value returned by a previous invocation of dlopen.handle
Return Values
If the referenced shared library was successfully closed, dlclose returns 0. If the shared library
cannot be closed or if the handle does not refer to an open shared library, the dlclose routine
returns a non-0 value. For more detailed diagnostic information you can use the dlerror routine.
Description
The dlclose routine disassociates a shared library previously opened by the dlopen routine
from the current process. Once a shared library has been closed using the dlclose routine, the
dlsym routine 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. A 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 a shared library is closed by dlclose, referencing symbols contained in that shared
library can cause undefined behavior.
Using dlclose to unload a shared library
The following example shows how to use dlclose to unload a shared library:
void* handle;
int ret_value;
handle = dlopen("./lib1.so", RTLD_GLOBAL | RTLD_LAZY);if (handle == NULL) {
printf("%s\n", dlerror());
}
ret_value = dlclose(handle);
if (ret_value != 0) {
printf("%s\n", dlerror());
}
The dladdr Routine
The dladdr routine gets the symbolic information for an address.
Syntax
int dladdr(void *address, D1_info *dlip);
Table 30 Parameter
DescriptionParameter
address
A pointer to a D1_info structure. The structure must be allocated by the user.dlip
The dlopen Shared Library Management Routines 163