1DLOPEN(3)                  Linux Programmer's Manual                 DLOPEN(3)
2
3
4

NAME

6       dlclose, dlopen, dlmopen - open and close a shared object
7

SYNOPSIS

9       #include <dlfcn.h>
10
11       void *dlopen(const char *filename, int flags);
12
13       int dlclose(void *handle);
14
15       #define _GNU_SOURCE
16       #include <dlfcn.h>
17
18       void *dlmopen (Lmid_t lmid, const char *filename, int flags);
19
20       Link with -ldl.
21

DESCRIPTION

23   dlopen()
24       The  function dlopen() loads the dynamic shared object (shared library)
25       file named by the null-terminated string filename and returns an opaque
26       "handle"  for  the  loaded  object.  This handle is employed with other
27       functions in the dlopen API, such as  dlsym(3),  dladdr(3),  dlinfo(3),
28       and dlclose().
29
30       If  filename is NULL, then the returned handle is for the main program.
31       If filename contains a slash ("/"), then it is interpreted as a  (rela‐
32       tive or absolute) pathname.  Otherwise, the dynamic linker searches for
33       the object as follows (see ld.so(8) for further details):
34
35       o   (ELF only) If the executable file for the calling program  contains
36           a  DT_RPATH  tag,  and  does not contain a DT_RUNPATH tag, then the
37           directories listed in the DT_RPATH tag are searched.
38
39       o   If, at the time that the program was started, the environment vari‐
40           able  LD_LIBRARY_PATH was defined to contain a colon-separated list
41           of directories, then these are searched.  (As a  security  measure,
42           this  variable  is  ignored  for  set-user-ID and set-group-ID pro‐
43           grams.)
44
45       o   (ELF only) If the executable file for the calling program  contains
46           a  DT_RUNPATH  tag,  then  the  directories  listed in that tag are
47           searched.
48
49       o   The cache file  /etc/ld.so.cache  (maintained  by  ldconfig(8))  is
50           checked to see whether it contains an entry for filename.
51
52       o   The directories /lib and /usr/lib are searched (in that order).
53
54       If  the  object  specified by filename has dependencies on other shared
55       objects, then these are also automatically loaded by the dynamic linker
56       using  the  same  rules.  (This process may occur recursively, if those
57       objects in turn have dependencies, and so on.)
58
59       One of the following two values must be included in flags:
60
61       RTLD_LAZY
62              Perform lazy binding.  Resolve symbols only  as  the  code  that
63              references them is executed.  If the symbol is never referenced,
64              then it is never resolved.  (Lazy binding is performed only  for
65              function  references; references to variables are always immedi‐
66              ately bound when the shared  object  is  loaded.)   Since  glibc
67              2.1.1,  this flag is overridden by the effect of the LD_BIND_NOW
68              environment vari