的情況下,我創建一個使用dlsysm(剪切對象開放),但我收到以下錯誤:錯誤:從無效轉換`無效*`來`無效(*)()`在dlsysm
error: invalid conversion from "void*" to "void (*)()"
這裏是我的代碼:
#include<iostream>
#include<dlfcn.h>
using namespace std;
int main() {
void (*fnptr)();
void *handle;
handle = dlopen("./libtestshared.so",RTLD_LAZY);
if (!handle) {
cerr << "Cannot open library: " << dlerror() << '\n';
} else {
cout<<"Opening"<<'\n';
}
fnptr = dlsym(handle , "fun");
return 0;
}
你可以請提供的代碼,你得到的錯誤?很難看到這裏發生了什麼 – Stefano
#include #include using namespace std; int main() { void(* fnptr)(); void * handle; handle = dlopen(「./ libtestshared.so」,RTLD_LAZY); if(!handle) cerr <<「無法打開庫:」<< dlerror()<<'\ n'; } else { cout <<「Opening」<<'\ n'; } fnptr = dlsym(handle,「fun」); return 0; } –
Yugandhar
好的...我已經添加了格式爲您的代碼... – Stefano