Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > D


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


dlclose() — close a shared library


cc [flag ... ] file ... -ldl [library]...

#include <dlfcn.h> int dlclose(void *handle);

Multithread Usage

This routine is thread-safe.

NOTE: The dynamic loader serializes the loading and unloading of shared libraries in multithreaded applications using a recursive pthread mutex lock. See the HP-UX Linker and Libraries Online User Guide for more information.


dlclose() is one of a family of routines that give the user direct access to the dynamic linking facilities (using the -ldl option on the compiler or ld command line). dlclose() disassociates a shared object previously opened by dlopen() from the current process. Once an object has been closed using dlclose(), its symbols are no longer available to dlsym(). All objects loaded automatically as a result of invoking dlopen() on the referenced object (see dlopen(3C)) are also closed. handle is the value returned by a previous invocation of dlopen().


If the referenced object was successfully closed, dlclose() returns 0. If the object could not be closed, or if handle does not refer to an open object, dlclose() returns a non-0 value. More detailed diagnostic information is available through dlerror().


If dlclose() fails, a subsequent call to dlerrno() returns one of the following values.


Cannot apply relocation in library.


Cannot close library due to remaining dependencies.


Invalid handle.


Out of memory.


__thread_setcancelstate failed on entry to or exit from dlclose().


sigenable failed on exit from dlclose().


siginhibit failed on entry to dlclose().


Unknown handle.


A successful invocation of dlclose() does not guarantee that the objects associated with handle have actually been removed from the address space of the process. Objects loaded by one invocation of dlopen() may also be loaded by another invocation of dlopen(). The same object may also be opened multiple times. An object is not removed from the address space until all references to that object through an explicit dlopen() invocation have been closed and all other objects implicitly referencing that object have also been closed.

Once an object has been closed by dlclose(), referencing symbols contained in that object can cause undefined behavior.


dlerrno(3C), dlerror(3C), dlopen(3C), dlsym(3C).

Texts and Tutorials

HP-UX Linker and Libraries Online User Guide

(See the +help option)

HP-UX Linker and Libraries User's Guide

(See manuals(5) for ordering information)

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.