fglut/libfglut.a(freeglut_state.o): undefined reference to symbol 'XGetWindowAttributes'

痴心易碎 提交于 2020-01-06 05:26:20

问题


I am compiling a C++ program using make, this is the error i'm getting.

/usr/bin/ld: fglut/libfglut.a(freeglut_state.o): undefined reference to symbol 'XGetWindowAttributes'

//usr/lib/i386-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

Makefile:55: recipe for target 'morphlines' failed

make: *** [morphlines] Error 1

I'm beginner


回答1:


/usr/bin/ld: fglut/libfglut.a(freeglut_state.o):

This tells me you link libfglut statically (*.a is just an archive of object files). When you do this, you must link all dependencies as well, because with the object files from the static library actually compiled into your program, your program will depend on them.

Either link libfglut dynamically (this is the default with the GNU toolchain), so your program will depend on libfglut.so which will itself depend on libX11.so -- or add -lX11 after -lfglut on the command line of your final linking step. You might need -Wl,-Bdynamic before -lX11 to switch the linker back to dynamic linking.

If this doesn't directly solve your problem, I suggest you edit your question to include the relevant parts of the Makefile you're using.



来源:https://stackoverflow.com/questions/44634459/fglut-libfglut-afreeglut-state-o-undefined-reference-to-symbol-xgetwindowatt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!