用dlopen和dlsym得到的函数指针,在dlclose后还能继续使用么? - Linux/Unix社区 / 程序开发区
来源:百度文库 编辑:神马文学网 时间:2024/10/04 06:09:32
共享对象通过dlopen动态加载动态库的
加载完成后,通过dlsym定位到你需要执行的函数指针
然后可以在程序中使用
当不需要使用的时候,再执行dlclose卸载掉动态链接库
自己去一个个函数man一下就明白了,顺手贴给你
Example:
加载完成后,通过dlsym定位到你需要执行的函数指针
然后可以在程序中使用
当不需要使用的时候,再执行dlclose卸载掉动态链接库
自己去一个个函数man一下就明白了,顺手贴给你
- C/C++ code
dlopen -- open a dynamically linked librarySyntax======cc . . . -lc#include
void *dlopen(const char *pathname, int mode);
- C/C++ code
dlsym -- get the address of a symbol in a dynamically linked librarySyntax======cc . . . -lc#include
void *dlsym(void *handle, const char *name);
Example:
- C/C++ code
void *handle;int i, *iptr;int (*fptr)(int);/* open the needed object */handle = dlopen("/usr/mydir/libx.so", RTLD_LAZY);/* find address of function and data objects */fptr = (int (*)(int))dlsym(handle, "some_function");iptr = (int *)dlsym(handle, "int_object");/* invoke function, passing value of integer as a parameter */i = (*fptr)(*iptr);
- C/C++ code
dlclose -- close a dynamically linked librarySyntax======cc . . . -lc#include
int dlclose(void *handle);Description===========dlclose(S) disassociates a shared object (a dynamically linked library inour case) previously opened by dlopen(S) from the current process. Once anobject has been closed using dlclose( ), its symbols are no longeravailable to dlsym(S). All objects loaded automatically as a result ofinvoking dlopen( ) on the referenced object are also closed. handle is theinvoking dlopen( ) on the referenced object are also closed. handle is thevalue returned by a previous invocation of dlopen( ).Return values=============If the referenced object was successfully closed, dlclose( ) returns 0. Ifthe object could not be closed, or if handle does not refer to an openobject, dlclose( ) returns a non-zero value. More detailed diagnosticinformation is available through dlerror(S).Notes=====A successful invocation of dlclose( ) does not guarantee that the objectsassociated with handle have actually been removed from the address space ofthe process. Objects loaded by one invocation of dlopen( ) may also beloaded by another invocation of dlopen( ). The same object may also beopened multiple times. An object is not removed from the address spaceuntil all references to that object through an explicit dlopen( )invocation have been closed and all other objects implicitly referencingthat object have also been closed.associated with handle have actually been removed from the address space ofthe process. Objects loaded by one invocation of dlopen( ) may also beloaded by another invocation of dlopen( ). The same object may also beopened multiple times. An object is not removed from the address spaceuntil all references to that object through an explicit dlopen( )invocation have been closed and all other objects implicitly referencingthat object have also been closed.Once an object has been closed by dlclose( ), referencing symbols containedin that object can cause undefined behavior.See also========dlerror(S), dlopen(S), dlsym(S)Standards conformance=====================dlclose(S) is not part of any currently supported standard; it is anextension of AT&T System V provided by The Santa Cruz Operation, Inc.
用dlopen和dlsym得到的函数指针,在dlclose后还能继续使用么? - Linux/Unix社区 / 程序开发区
dlopen dlsym dlclose解析 - yujixi123的专栏 - CSDN博客
【转】__attribute__((packed)) 指针传递,赋值错误问题。 - Linux/Unix社区 / 程序开发区
用GCC将源文件编译成库文件的问题 Linux/Unix社区 / 程序开发区
用GCC将源文件编译成库文件的问题 Linux/Unix社区 / 程序开发区
用GCC将源文件编译成库文件的问题 Linux/Unix社区 / 程序开发区 - CSDN社区 community.csdn.net
函数指针和指针函数
函数指针和指针函数
关于C++中函数指针的使用
Makefile一问:如何修改.o输出文件的输出路径 Linux/Unix社区 / 程序开...
指针函数和函数指针 zz
如何安装SUN公司的SOLARIS操作系统------(unix)50分呀!!! Linux/Unix社区 / 系统维护与使用区 - CSDN社区 community.csdn.net
Linux中select函数的使用
C语言再学习 之 函数指针和指针函数
GetProcAddress()、函数指针和 C++ - csuhkx的日志 - 网易博客
函数指针的另类用法
typedef 函数指针的用法
Linux和Unix系统的关系和区别详细介绍
指针数组和数组指针 - 酸菜猪蹄的程序人生 - C 博客
LINUX和MINIX(微型UNIX)的论战
Unix系统的攻击和防范 - Linux伊甸园----Linuxeden_com-Linu...
C51指针的使用
函数指针
函数指针