Reputation: 446
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
Upvotes: 0
Views: 1387
Reputation: 162307
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} …)
Upvotes: 1