6 .Nd load and link a dynamic library or bundle
10 .Fn dlopen "const char* path" "int mode"
13 examines the mach-o file specified by
15 If the file is compatible with the current process and has not already been
16 loaded into the current process, it is loaded and linked. After being linked,
17 if it contains any initializer functions, they are called, before
21 can load dynamic libraries and bundles. It returns a handle that can
28 with the same path will return the same handle, but the internal reference
29 count for the handle will be incremented. Therefore all
31 calls should be balanced with a
35 If a null pointer is passed in
38 returns a handle equivalent to RTLD_DEFAULT.
43 It must contain one or more of the following values, possibly ORed together:
45 .Bl -tag -width RTLD_LAZYX
47 Each external function reference is bound the first time the function is called.
49 All external function references are bound immediately during the call to
54 is normally preferred, for reasons of efficiency.
57 is useful to ensure that any undefined symbols are discovered during the
61 RTLD_LAZY nor RTLD_NOW is specified, the default is RTLD_LAZY.
63 One of the following flags may be ORed into the
66 .Bl -tag -width RTLD_LOCALX
68 Symbols exported from this image (dynamic library or bundle) will be available to any
69 images build with -flat_namespace option to
73 when using a special handle.
75 Symbols exported from this image (dynamic library or bundle) are generally hidden
78 when directly using the handle returned by this call to
83 RTLD_GLOBAL nor RTLD_LOCAL is specified, the default is RTLD_GLOBAL.
85 One of the following may be ORed into the
88 .Bl -tag -width RTLD_NODELETEX
90 The specified image is not loaded. However, a valid
92 is returned if the image already exists in the process. This provides a way
93 to query if an image is already loaded. The
95 returned is ref-counted, so you eventually need a corresponding call to
98 The specified image is tagged so that will never be removed from the address space,
99 even after all clients have released it via
103 Additionally, the following may be ORed into the
106 .Bl -tag -width RTLD_FIRSTX
110 is tagged so that any
114 will only search the image specified, and not subsequent images. If
116 is NULL and the option RTLD_FIRST is used, the
118 returned will only search the main executable.
122 searches for a compatible Mach-O file in the directories specified by a set of environment variables and
123 the process's current working directory.
124 When set, the environment variables contain a colon-separated list of directory paths,
125 which can be absolute or relative to the current working directory.
129 does not contain a slash character (i.e. it is just a leaf name),
131 searches the following until it finds a compatible Mach-O file: $LD_LIBRARY_PATH,
132 $DYLD_LIBRARY_PATH, current working directory, $DYLD_FALLBACK_LIBRARY_PATH.
136 looks like a framework path (e.g. /stuff/foo.framework/foo),
138 searches the following until it finds a compatible Mach-O file:
139 $DYLD_FRAMEWORK_PATH (with framework partial path from
143 (using current working directory for relative paths), then
144 $DYLD_FALLBACK_FRAMEWORK_PATH (with framework partial path from
150 contains a slash but is not a framework path (i.e. a full path or a partial path to a dylib),
152 searches the following until it finds a compatible Mach-O file:
153 $DYLD_LIBRARY_PATH (with leaf name from
157 (using current working directory for relative paths), then
158 $DYLD_FALLBACK_LIBRARY_PATH (with leaf name from
162 Note: If DYLD_FALLBACK_LIBRARY_PATH is not set, dlopen operates as if
163 DYLD_FALLBACK_LIBRARY_PATH was set to $HOME/lib:/usr/local/lib:/usr/lib.
165 Note: If DYLD_FALLBACK_FRAMEWORK_PATH is not set, dlopen operates as if
166 DYLD_FALLBACK_FRAMEWORK_PATH was set to $HOME/Library/Frameworks:/Library/Frameworks:/Network/Library/Frameworks:/System/Library/Frameworks.
168 Note: There are no configuration files to control dlopen searching.
170 Note: If the main executable is a set[ug]id binary or codesigned with entitlements,
171 then all environment variables are ignored, and only a full path can be used.
173 Note: Mac OS X uses "universal" files to combine 32-bit and 64-bit libraries. This means there are no separate 32-bit and 64-bit search paths.
178 fails, it returns a null pointer, and sets an error condition which may be interrogated with
182 .Xr dlopen_preflight 3