[CMake] Using target_link_libraries

Colin Michael Diesh diesh at colorado.edu
Sat Mar 27 20:57:10 EDT 2010


Hey, I was trying to use the TARGET_LINK_LIBRARIES in a CMakeLists.txt file but the linking doesn't end up working. I am using cygwin and CMake 2.6.4

Currently, I am having trouble with the OpenGL libraries. It links GLUT but not the OpenGL libraries.


CMakeLists.txt
----------------
...
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(GLUT)
...
SET(program_LIBS ${program_LIBS} ${GLUT_LIBRARIES} )
SET(program_LIBS ${program_LIBS} ${OPENGL_LIBRARIES} )
...
ADD_EXECUTABLE(tiney ${program_SRCS})
TARGET_LINK_LIBRARIES(program ${program_LIBS})
...
----------------------



Doing MESSAGE(STATUS "${program_LIBS}") gives

-- /lib/libglut.dll.a;/usr/lib/w32api/libglu32.a;/usr/lib/w32api/libopengl32.a;/usr/X11R6/lib/libGLEW.a



CMakeFiles/program.dir/link.txt says this
----------------------------
/usr/bin/gcc.exe  -O3 -DNDEBUG   CMakeFiles/tiney.dir/main.c.o  -o tiney.exe -Wl,--out-implib,libtiney.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lglut /usr/lib/w32api/libglu32.a /usr/lib/w32api/libopengl32.a /usr/X11R6/lib/libGLEW.a 
----------------------------


So it links GLUT correctly, but the opengl libraries do not get linked, they do not have '-l'. Is there any way I can fix this?

Note: it also doesn't work for another library, libGLEW.a.

-Colin





More information about the CMake mailing list