我创建了一个简单的 C++ 应用程序。我可以编译它,它工作正常。但是现在我需要动态加载库,并且我已经将 dlfnc.h 添加到我的项目中并添加了更多代码:
#include <iostream>
#include <dlfcn.h>
void *mylib;
int eret;
using namespace std;
int main() {
mylib = dlopen("mylib.so", RTLD_LOCAL | RTLD_LAZY);
eret = dlclose(mylib);
cout << "!!!Hello, World!!!" << endl; // Prints !!!Hello, World!!!
return 0;
}
编译:
cd ~/workspace/LinuxGcc/src
g++ LinuxGcc.cpp
我得到一个编译错误:
/tmp/ccxTLiGY.o: In function `main':
LinuxGcc.cpp:(.text+0xf): undefined reference to `dlopen'
LinuxGcc.cpp:(.text+0x25): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
dlfcn.h
存在于/usr/include/
。
问题出在哪里?
最佳答案
关于c++ - 修复对 dlopen() 和 dlcose() 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33035712/