Linux dynamic library function Introduction

Source: Internet
Author: User

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 ");

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.