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来查找函数,

猜你喜欢

转载自www.cnblogs.com/qianqiannian/p/11762651.html
今日推荐