C++ GL linker undefined reference

我的未来我决定 提交于 2019-12-13 07:18:02

问题


Using Ubuntu 14.04, g++, I want to port a project from make to cmake. Getting the following error when I sudo make install.

Linking CXX executable texmapper
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../..
/lib/libplibssg.a(ssgLeaf.o): undefined reference to symbol 'glNewList'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libGL.so: 
error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

A linker error like many encountered on this website. But the usually suggested fix, "-lGL -lGLU -lglut, does not work. I also tried some permutations of this.

Before the undefined reference to glNewList I had an undefined reference to glPopClientAttrib, which I solved by adding lGL, like this:

set(CMAKE_CXX_FLAGS "-lGL")

So I am on the right track, but the answer is eluding me.

Edit: full command (verbose):

/usr/bin/c++   -lGLEW -lGL -lGLU -lglut    CMakeFiles/texmapper.dir/maintexmapper.o CMakeFiles/texmapper.dir/ssgSaveAC.o  -o texmapper -rdynamic -Wl,-Bstatic -lplibsg -lplibssg -lplibul -Wl,-Bdynamic ../../libs/tgf/libtgf.so ../../libs/tgfclient/libtgfclient.so -lglut -lXmu -lXi -lpng -lz -lSM -lICE -lX11 -lXext -lXrandr -Wl,-rpath,/home/jeroen/Thesis/torcsCMAKE/trunk/src/libs/tgf:/home/jeroen/Thesis/torcsCMAKE/trunk/src/libs/tgfclient

回答1:


With CMake the required libraries are set using the target_link_libraries command. Usually you'll use find_package(OpenGL) to collect the locations of the OpenGL development and library files and use the package variables for the target_link_libraries command. Like this:

find_package(OpenGL)
add_executable(foo …)
target_link_libraries(foo ${OPENGL_gl_LIBRARY} …)


来源:https://stackoverflow.com/questions/36457998/c-gl-linker-undefined-reference

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