standard. Rtld_noload: The library is not loaded. Can be used to test whether the library has been loaded (Dlopen () returns null if the description is not loaded, otherwise the description has been loaded), or it can be used to change the flag of the loaded library, such as: Flag for the previously loaded library is rtld_local, with Dlopen (rtld_noload| RTLD_GLOBAL) flag will become Rtld_global. This flag
. However, this function must be declared with the extern "C" qualifier to prevent its symbolic name from being mangle.Example 1. Load the function code:
//----------// Main. cpp://----------# Include # Include Int main (){Using STD: cout;Using STD: cerr; Cout // open the library cout void * handle = dlopen (". /Hello. so ", rtld_lazy); If (! Handle) { cerr
return 1;
} // load the symbol
cout typedef void (* hello_t)
DLOPEN? Dlmopen? Dlclosename???? Dlclose, Dlopen, Dlmopen -open/close shared objectsSynopsis#include Descriptiondlopen ()???? This function loads a dynamic shared object (shared library) file named after a null-terminated string file name, and returns an opaque "handle" for the loaded object. This handle is used with other functions in the Dlopen API, for
Dlsym, as in C. However, the function is declared with an extern "C" qualifier to prevent its symbol name from being mangle.
Example 1. Load function
Code:
//----------
Main.cpp:
//----------
#include #include
int main ()
{
Using Std::cout;
Using Std::cerr;
cout
Open the Library
cout void* handle = Dlopen ("./hello.so", Rtld_lazy);
if (!handle) {
Cerr return 1;
}
Load the symbol
cout typedef void (*
changes in the current version. Why are there errors?Question 2: The check_vrf_r symbol is not used in libilvrfplugin. so. Why cannot I find the symbol? Search for ProblemsLocate the error code based on the clues in Syslog:
...lib_handle=dlopen(ep[count]->d_name,RTLD_LAZY);if(!lib_handle){ error = dlerror(); TRACER(TRC_INFO)
Here, dlopen () is used to load the dynamic link library, and the flag is
DlopenBasic definition Function: Open a dynamic link library contains header file: #include function definition: void * Dlopen (const C Har * pathname, int mode); function Description: Opens the specified dynamic connection library file in the specified mode in the Dlopen () function, and returns a handle to the calling process. Use Dlclose () to unload the open library. Mode: Divided into thes
Dynamically Loaded (DL)
These two functions are found when reading Hal-related source code.
In short, after the shared object is loaded by dynamically opening the dynamic library through dlopen, a handle is returned, and the function pointer you need to execute is located through dlsym, which can then be used in the program.
Dlopen -- open a dynamically linked Library
Dlsym -- get the address of a symbolI
problem sometimes you want to load a library (and use the function) at runtime ), this often happens when you write some plug-ins or module architectures for your Program . in C language, it is easy to load a library (it is enough to call dlopen, dlsym, and dlclose), but the situation is a little complicated for C ++. Part of the difficulty of loading a C ++ library dynamically is that C ++'s name mangling (Translator's note: Some people translate
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_no
Source: http://www.eifr.com/article.php? Id = 1766 page = 2
In Linux, dlopen, dlsym, and dlclose are equivalent to loadlibrary, getprocaddress, and freelibrary on windows. They can dynamically load dynamic libraries at runtime and use the export functions. But the limitation is that, in this way, only global functions can be exported, rather than class methods. Therefore, a large number of global functions will be designed to encapsulate the functio
Differences between several flags in dlopen: rtld_lazy rtld_now rtld_global
Void * dlopen (const char * filename, int flag );Flag: rtld_lazy rtld_now rtld_global, which has the following meanings:1. rtld_lazy: Before dlopen returns, do not parse undefined variables (such as external variables extern or functions) in the dynamic library, the address o
Void * dlopen (const char * filename, int flag );
Flag: rtld_lazy rtld_now rtld_global, which has the following meanings:
Rtld_lazy: Before dlopen returns, do not parse undefined variables (such as the external variable extern or function) in the dynamic library, that is, do not parse the address of the variable.
Rtld_now: different from above, he needs to parse the address of each undefined variable before
There are two dynamic link libraries, one of which depends on another defined function. When using dlopen, you need to add RTLD_GLOBAL.
Dynamic library 1, life, defines a life function.
Gcc-shared-Wl,-soname, liblife. so.1-o liblife. so.1.0 life. c
---------------------------------------------------------------------
# Include # Include # Include
Int life (int){Return a + 8;}
Dynamic library 2, printk, which calls the life function of the dynamic l
To compile a dynamic library, you must add the "-shared" option. When compiling the dynamic library d1.so, if the content of the dynamic library d2.so is used, you only need to add the header file directory (-I) of d2.so, without specific implementation.CodeThis basically achieves the independence of D1 and D2.
When compiling the executable body, all libraries (-L and-l) must be added, and the related header file directory (-I) must also be added, in addition, the "-LDL" parameter must be add
under Linux sometimes compiled source files may have syntax errors, but many times still can generate dynamic library, this time, with dlopen Open There is no way to return a handle, resulting in a dynamic library can be generated, but not open, this time the best way is not Dlopen A method that is called dynamically, but instead uses a static call method. 1, in the test file with a static call the required
use and examples of Dlopen, Dlsym and Dlclose
I've never had time to clean up these three functions before. Take the time to tidy up today.
1. Introduction to function
Dlopen
Basic definition
Function: Open a dynamic link libraryInclude header file:#include function definition:void * Dlopen (const char * pathname, int mode);Function Description:The
Questions :Development platform *.so plug-in when encountering the same function name appears in different. So files, assuming that a.so and b.so,b.so to use the definition function a () in a.so, and Dlopen will load a.so and then load b.so, when b.so is opened, A null pointer error is reported.Basic Concepts :The ODR is interpreted in the C + + standard as:1. No compilation unit can contain variables, functions, enumerations, classes, or templates de
First look at the situation (careful headache)
Client. C compiled to obtain the client; dlopen (". /LIBA. so ", rtld_lazy | rtld_global) Open LIBA. so, and call LIBA. the START function in so; in LIBA. the start_fcn function in so tries to call the startup_fcn function in the client through the handle obtained by dlopen (0, rtld_global | rtld_lazy. Use GCC client. c-o client-LDL obtains the client and GCC-F
1, Dlopen Dynamic Library failure reasons, I met mainly the following points (after encountering new problems, then perfect, first hit a point)① Dynamic Library Location There is no lil bit place, Dlopen can not find the dynamic library you want to operateWorkaround: Drop to the specified directory.② header file does not have a full package, there are unrecognized functions or identifiersWorkaround: Add a p
1. Program Library howtoHttp://www.dwheeler.com/program-library/Program-Library-HOWTO/index.html
2. c ++ dlopen mini howtoHttp://www.isotton.com/howtos/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html
3. Dynamic class loading for C ++ on LinuxHttp://www.linuxjournal.com/article/3687
After that, if C ++ stipulated that the name mangling should follow certain
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.