Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

linux - undefined reference to `dlopen'

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...