dlsym用法


1. 包含头文件 #include<dlfcn.h>

2. 函数定义 void *dlsym(void *handle, const char* symbol);

handle是使用dlopen函数之后返回的句柄,symbol是要求获取的函数的名称,函数,返回值是void*,指向函数的地址,供调用使用

dlsym与dlopen的以如下例子解释:

#include<dlfcn.h>

void * handle = dlopen("./testListDB.so",RTLD_LAZY);

如果createListDB函数定义为int32_t createListDB(std::string);

那么dlsym的用法则为:int32_t  (*create_listDB)(std::string) = reinterpret_cast<int32_t (*)(std::string)>(dlsym(handle, "createListDB"))

createListDB库函数的定义要用extern来声明,这样在主函数中才能通过createListDB来查找函数,

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM