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來查找函數,