dlopen usage

1. include the header file #include <dlfcn.h>

2. The function definition void * dlopen (const char * pathName , int mode);

pathName refers to the location in the file db real machine environment, mode refers to the open database schema

mode under linux, according to the functions are the following

Analytical methods:

RTLD_LAZY: defer the decision, before dlopen returns, for dynamic library undefined symbol does not perform parsing (only valid for function references for variable references are always resolved immediately)

RTLD_NOW: decision immediately, before dlopen returns, resolve all undefined symbols. If the resolution does not come out, in dlopen returns NULL, the error is undefined symbol: XXX ...

Range:

RTLD_GLOBAL: dynamic library symbols defined in other libraries may be opened subsequent relocation

RTLD_LOCAL: RTLD_GLOBAL opposite effect and other dynamic library symbols defined in the library can not be opened subsequent relocation. If it did not specify RTLD_GLOBAL or RTLD_LOCAL, then

The default is RTLD_LOCAL.

Mode of action:

RTLD_NODELETE: not unload during dlclose () library, and after using dlopen () library does not initialize static variables reload the library. This flag is not POSIX-2001 standard.

RTLD_NOLOAD: do not load the library can be used to test whether the library has been loaded (dlopen () returns NULL description is not loaded, or load instructions), can also be used to change the flag library has been loaded,

Such as: the previously loaded library flag is RTLD_LOCAL, with dlopen (RTLD_NOLOAD | RTLD_GLOBAL) after the flag will become RTLD_GLOBAL this flag is not POSIX-2001 standard.

RTLD_DEEPBIND: In the first search before searching the global symbol library of symbols, symbols of the same name to avoid conflict, this flag is not POSIX-2001 standard

 

3. Return value void *, if successful returns a reference to the handle of the database, if it fails returns NULL

To join -ldl (designated dl library) compile time

ey:gcc test.c -o test -ldl

 

Guess you like

Origin www.cnblogs.com/qianqiannian/p/11762646.html