Dynamically load a module into the calling process.
#include <dlfcn.h>
void *dlopen (FilePath, Flags); const char *FilePath; int Flags;
The dlopen subroutine loads the module specified by FilePath into the executing process's address space. Dependents of the module are automatically loaded as well. If the module is already loaded, i t is not loaded again, but a new, unique value will be returned by the dlopen subroutine.
The value returned by dlopen may be used in subsequent calls to dlsym and dlclose. If an error occurs during the operation, dlopen returns NULL.
If the main application was linked with the -brtl option, then the runtime linker is invoked by dlopen. If the module being loaded was linked with runtime linking enabled, both intra-module and inter-module references are overridden by any symbols available in the main application. If runtime linking was enabled, but the module was not built enabled, then all inter-module references will be overridden, but some intra-module references will not be overridden.
If the module being opened with dlopen or any of its dependents is being loaded for the first time, initialization routines for these newly-loaded routines are called (after runtime linking, if applicable) before dlopen returns. Initialization routines are the functions specified with the -binitfini: linker option when the module was built. (Refer to the ld command for more information about this option.)
Notes:
- The initialization functions need not have any special names, and multiple functions per module are allowed.
- If the module being loaded has read-other permission, the module is loaded into the global shared library segment. Modules loaded into the global shared library segment are not unloaded even if they are no longer being used. Use the slibclean command to remove unused modules from the global shared library segment.
Use the environment variable LIBPATH to specify a list of directories in which dlopen search es for the named module. The running application also contains a set of library search paths that were specified when the application was linked; these paths are searched after any paths found in LIBPATH. Also, the setenv subroutine
Specifies variations of the behavior of dlopen. Either RTLD_NOW or RTLD_LAZY must always be specified. Other flags may be OR'ed with RTLD_NOW or RTLD_LAZY.
Upon successful completion, dlopen returns a value that can be used in calls to the dlsym and dlclose subroutines. The value is not valid for use with the loadbind and unload subroutines.
If the dlopen call fails, NULL (a value of 0) is returned and the global variable errno is set. If errno contains the value ENOEXEC, further information is available via the dlerror function.
See the load subroutine for a list of possible errno values and their meanings.
This subroutine is part of Base Operating System (BOS) Runtime.
The dlclose subroutine, dlerror subroutine, dlsym subroutine, load subroutine, loadbind subroutine, loadquery subroutine, unload subroutine.
The ld command.
Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.