问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen