[CMake] Using target_link_libraries
Michael Wild
themiwi at gmail.com
Sun Mar 28 03:51:19 EDT 2010
On 28. Mar, 2010, at 1:57 , Colin Michael Diesh wrote:
> 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
There seems to be nothing wrong here... If possible, CMake prefers to link using the full path instead of relying on the -l flag. This is mainly because using -L and -l it is very difficult to ensure which library is linked if there are more than one library by that name on the linker path. Also, the linker will usually prefer dynamic libraries over static ones, unless forced with a special flag, but then that flag acts on all libraries, not just one.
Michael
More information about the CMake
mailing list