HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)
d
dlopen(3C) dlopen(3C)
NAME
dlopen(), dlopene() - open a shared library, open a shared library with explicit load address (64-bit only)
SYNOPSIS
cc [flag]... cfile...
-ldl [library]...
#include <dlfcn.h>
void *dlopen(const char *file, int mode);
void *dlopene(const char *file, int mode, struct dlopen_opts *opts);
Multithread Usage
These routines are thread-safe.
NOTE: The dynamic loader dld.sl serializes the loading and unloading of shared libraries in mul-
tithreaded applications using a recursive pthread mutex lock. See the HP-UX Linker and Libraries
Online User Guide for more information.
DESCRIPTION
dlopen() and dlopene() are members 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).
dlopen() makes a shared object specified by a file available to a running process. A shared object may
specify other objects that it "needs" in order to execute properly. These dependencies are specified by
DT_NEEDED entries in the .dynamic section of the original object. Each needed object may, in turn,
specify other needed objects. All such objects are loaded along with the original object as a result of the call
to dlopen().
dlopene() is an extension to dlopen() which allows the caller to specify explicitly the placement of a
shared library’s text and data segment when the library is dynamically loaded.
A successful dlopen() or dlopene() call returns to the process a handle which the process may use on
subsequent calls to dlsym() and dlclose() . This value should not be interpreted in any way by the
process.
file is used to construct a path name to the object file. If file contains a slash character, the file argument
itself is used as the path name. Otherwise
dlopen() searches a series of directories, in the following
order, for file:
• Any directories specified by the dynamic path set by calling dlsetlibpath()
.
• Any directories specified by the environment variable
LD_LIBRARY_PATH
.
• Any directories specified by
SHLIB_PATH .
• For ELF applications, any directories specified by a
DT_RPATH entry in the .dynamic section of
the original program object.
• The directories
/usr/lib and usr/ccs/lib in 32-bit mode and /usr/lib/pa20_64
and
/usr/ccs/lib/pa20_64
in 64-bit mode.
• The current working directory.
The use of
SHLIB_PATH is static. This means that when the program starts, the dynamic loader dld
uses the value in environment variable SHLIB_PATH . Any change to SHLIB_PATH during the program
execution has no effect. The dld_getenv() function removes this constraint. With dld_getenv()
you can change the SHLIB_PATH value (using putenv) and call dld_getenv() to cause dld to read
current SHLIB_PATH value. You can use this new SHLIB_PATH value for subsequent library searching.
You can use dld_getenv() while loading shared libraries using shl_load() or dlopen() .As
described earlier, you should enable SHLIB_PATH searching using the chatr +s enable option. In
case of shl_load() , you should use the DYNAMIC_PATH flag.
The following example demonstrates the dld_getenv() function:
#include <stdio.h>
#include <dl.h>
main(int argc, char **argv) {
char * str;
Section 3−−172 Hewlett-Packard Company − 1 − HP-UX 11i Version 1: September 2005