对'dlopen'的未定义引用

时间:2011-05-31 06:44:03

标签: linux gcc linker

我有一个程序不能使用现代GCC构建,并且输出效果不错:

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

我在互联网上搜索了建议,但只找到了将-ldl添加到链接器的建议。但这在这里没有用。我该怎么办?

1 个答案:

答案 0 :(得分:12)

移动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 
相关问题