本文介绍了修复对dlopen和dlcose的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了简单的c ++应用程序.我可以编译它,并且工作正常.但是现在我需要动态地加载库,并且已经在项目中添加了dlfnc.h并添加了更多代码:
I have created simple c++ application. I can compile it and t works fine. But now I need to load library dynamically and I have added dlfnc.h to my project and added some more code:
#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;
}
编译:
myname@ubuntu:~/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/
哪里有问题?
推荐答案
dlopen(3):
dlopen(3):
Link with -ldl.
如此
g++ LinuxGcc.cpp -ldl
会没事的.
这篇关于修复对dlopen和dlcose的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!