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