Dlopen()
Function:Open a dynamic link library
Include header file:
# Include <dlfcn. h>
Function Definition:
Void * dlopen (const char *Pathname, IntMode);
Function Description:
InDlopenTo open the specified dynamic connection library file in the specified mode, and return a handle to the calling process. UseDlclose() To uninstall the opened library.
Mode is an open mode with multiple values. different operating systems have different functions. In Linux, there are three types of functions:
1. Resolution Method
Rtld_lazy: Do not parse undefined symbols in the dynamic library before dlopen returns (only valid for function reference and always parse variable reference immediately ).
Rtld_now: all undefined symbols need to be parsed before dlopen returns. If the undefined symbols cannot be parsed, null will be returned in dlopen with the error: Undefined Symbol: XXXX .......
2. Scope of action, which can be used in combination with the resolution method through "|.
Rtld_global: The symbols defined in the dynamic library can be relocated by other libraries opened later.
Rtld_local: In contrast to rtld_global, the symbols defined in the dynamic library cannot be relocated by other libraries opened later. If rtld_global or rtld_local is not specified, the default value is rtld_local.
3. Method of action
Rtld_nodelete: Do not uninstall the database during dlclose () and do not initialize static variables in the database when you use dlopen () to reload the database. This flag is not POSIX-2001 standard.
Rtld_noload: the database is not loaded. It can be used to test whether the database has been loaded (if dlopen () returns NULL, it indicates that the database has not been loaded; otherwise, it indicates that the database has been loaded). It can also be used to change the flag of the loaded database, for example: the flag of the previously loaded library is rtld_local. After using dlopen (rtld_noload | rtld_global), the flag will become rtld_global. This flag is not POSIX-2001 standard.
Rtld_deepbind: Search for symbols in the database before searching for global symbols to avoid conflicts between symbols of the same name. This flag is not POSIX-2001 standard.
Return Value:
Return ErrorNull
Succeeded. Database reference is returned.
Add during compilation-LDL (SpecifyDLLibrary)
For example
GCC test. C-o Test-LDL