Use of dlopen in Linux

Source: Internet
Author: User
Tags posix types of functions

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

 

 

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.