我用下面的代碼片斷加載Linux上的so
庫:dlopen的作品,但對dlsym不
handle = dlopen("myLib.so", RTLD_LAZY);
if(handle == NULL) {
throw std::runtime_error("unable to load myLib.so");
}
再往下我然後嘗試訪問在so
的方法:
getter = dlsym(handle, "getMethod");
if(getter == 0) {
std::ostringstream msg;
msg << "missing entry point " << dlerror();
throw std::runtime_error(msg.str().c_str());
}
運行時,dlopen
階段沒有出現異常,但我不斷收到錯誤:
missing entry point undefined symbol: getMethod
運行在myLib.so
nm
顯示getMethod
:
> nm myLib.so | grep get
0000000000024220 T getMethod
我想,我也該方法使用extern "C"
爲好。
UPDATE
我現在懷疑的是,雖然手柄的NULL檢查不會導致異常,則可能是手柄本身的問題。
是否有無論如何我可以執行任何進一步的檢查,而不僅僅是== NULL,以確認電話的dlopen成功?
是否在nm中顯示'T'或't'?如果顯示「t」,表示該功能未被導出。方法名稱中是否有前導下劃線?你也應該在你的問題中顯示'nm'輸出。 – Petesh
添加到原文(顯示'T') – imrichardcole
能否提供一些關於如何創建.so文件的信息? – brm