Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Single UNIX Specification, Version 3 |
both | z/OS® V1R6 |
#define _UNIX03_SOURCE
#include <dlfcn.h>
void *dlopen(const char *file, int mode);
Makes the dynamic link library (DLL) specified by file available to the calling program.
If the file argument begins with two slashes ("//"), then an attempt is made to load the DLL from the caller's MVS™ load library search order (in order: STEPLIB/JOBLIB, LPA, Link List). The DLL name must be eight characters or less, and is converted to uppercase.
Under the CICS® environment, the search sequence for DLL load modules is the same as that used for dynamically loaded CICS modules. Loading DLLs from the z/OS UNIX file system is not supported under CICS.
For more information about how DLLs are loaded and how the search sequence is used, see the topic about in z/OS Language Environment Programming Guide.
A successful call returns a handle which the caller may use on subsequent calls to dlsym() and dlclose(). The value of this handle should not be interpreted in any way by the caller.
Only a single copy of a DLL is brought into the address space, even if invoked multiple times for the same DLL, and even if different values of the file parameter are used to reference the same DLL.
The mode parameter describes how dlopen() operates on a file with respect to the processing of dependent DLLs and the scope of visibility of the symbols provided within file. If a file is specified in multiple invocations, mode is interpreted at each invocation. The mode is a bitwise-OR of the values specified.
Mode Values
If a subsequent call is made for this same DLL with a mode of RTLD_GLOBAL, then the DLL will maintain the RTLD_GLOBAL status regardless of any previous or future specification of RTLD_LOCAL, as long as the DLL remains loaded (see dlclose()).
If the value of file is NULL, dlopen() returns a "global symbol object" handle. This object will provide access (via dlsym()) to the symbols exported from:
Symbols introduced by the call to dlopen() for a DLL, and available through dlsym(), are those which are exported by the DLL. Typically such symbols will be those identified by a #pragma export in C, or with the EXPORTALL compile option. For details on how to specify exported data and functions, for C/C++ as well as other languages, see the topic about building a simple DLL in z/OS Language Environment Programming Guide
The following example illustrates use of dlopen() and dlclose():
...
/* Open a dynamic library and then close it ... */
#include <dlfcn.h>
void *mylib;
int eret;
mylib = dlopen("mylib.so", RTLD_LOCAL | RTLD_LAZY);
...
eret = dlclose(mylib);
...