未定义的参考`dlopen' [英] undefined reference to `dlopen'

查看:212
本文介绍了未定义的参考`dlopen'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  gcc -I / usr / lib我有一个程序不能用现代GCC构建。 / qt3 / include -I / opt / kde3 / include / -fmessage-length = 0 -O2 -Wall -D_FORTIFY_SOURCE = 2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt -mt -ldl -L / usr / lib / qt3 / lib64 -o autocheck autocheck.cpp 
autocheck.cpp:在函数'int main(int,char **)'中:
autocheck.cpp:64:62:warning:格式许多参数
autocheck.cpp:79:79:警告:格式太多的参数
/tmp/ccOFReGf.o:在函数`main'中:
autocheck.cpp :(。文本+ 0x244):对`dlopen'的未定义引用
autocheck.cpp :(。text + 0x2e1):对`dlerror'的未定义引用
collect2:ld返回1退出状态

我搜索了Internet的建议,但只找到了将-ldl添加到链接器的建议。但这在这里没有帮助。我应该怎么做? 解决方案

移动autocheck.cpp,使其位于命令中的库之前。只搜索库中需要解析的文件,这些文件出现在它们之前。所以你的命令应该是这样的:

  gcc autocheck.cpp -I / usr / lib / qt3 / include -I / opt / kde3 / include / -fmessage-length = 0 -O2 -Wall -D_FORTIFY_SOURCE = 2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt -mt -ldl -L / usr / lib / qt3 / lib64  - o autocheck 


I have a program that does not build with modern GCC with the foollowing output:

gcc -I/usr/lib/qt3/include -I/opt/kde3/include/  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt-mt -ldl -L/usr/lib/qt3/lib64 -o autocheck autocheck.cpp
autocheck.cpp: In function 'int main(int, char**)':
autocheck.cpp:64:62: warning: too many arguments for format
autocheck.cpp:79:79: warning: too many arguments for format
/tmp/ccOFReGf.o: In function `main':
autocheck.cpp:(.text+0x244): undefined reference to `dlopen'
autocheck.cpp:(.text+0x2e1): undefined reference to `dlerror'
collect2: ld returned 1 exit status

I searched the Internet for advise but only found a recommendation to add -ldl to the linker. But this does not help here. What should I do?

解决方案

Move autocheck.cpp so that it is before the libraries in your command. Libraries are only searched for things that need resolving in files that appear before them. So your command should look like this:

gcc autocheck.cpp -I/usr/lib/qt3/include -I/opt/kde3/include/  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt-mt -ldl -L/usr/lib/qt3/lib64 -o autocheck 

这篇关于未定义的参考`dlopen'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆