Header file # include <dlfcn. h>
Load dynamic library
Void * dlopen (const char * filename, int flag );
Possible flag values:
L rtld_lazy
L rtld_now
L rtld_global
L rtld_local
L rtld_nodelete (since glibc 2.2)
L rtld_noload (since glibc 2.2)
L rtld_deepbind
The specific meanings of these flags can be viewed by man.
Returns the most recent error in the dynamic library.
Char * dlerror (void );
Return the function address based on the dynamic library handle and function name.
Void * dlsym (void * handle, const char * symbol );
If you use dlopen (null, <flag>) to obtain the handle, you can use this handle to find all function symbols, as long as the DLL where the function symbol is located specifies rtld_global during loading
Disable dynamic library
Int dlclose (void * handle );
Return the function name and other information based on the function address.
Note that the input address only falls within the range of the function code space and does not need to be the start address of the function.
Int dladdr (void * ADDR, dl_info * info );
Typedef struct {
Const char * dli_fname;/* filename of defining object */
Void * dli_fbase;/* load address of that object */
Const char * dli_sname;/* Name of nearest lower symbol */
Void * dli_saddr;/* exact value of nearest symbol */
} Dl_info;
Constructor and destructor (these two are attributes, not functions)
_ Attribute _ (constructor ))
_ Attribute _ (destructor ))
For example:
_ Attribute _ (constructor) void before_main ()
{
Printf ("before Main/N ");
}
_ Attribute _ (destructor) void after_main ()
{
Printf ("after main/N ");
}