Robert
Robert

Reputation: 6437

cmake: altering the linker command

This probably very easy when you know how, but I don't :)

I'm trying to build some code that takes uses opengl/glut. I'm using the cygwin version of cmake opengl etc. The only reference I see to opengl/gult is in the CMakeLists.txt:

find_package(OpenGL REQUIRED)
find_package(GLU REQUIRED)
find_package(GLUT REQUIRED)

Everything works fine up till the linking stage, which ends with:

CMakeFiles/glview.dir/glview.c.o: In function `DrawGLScene': /cygdrive/C/code/libfreenect/examples/glview.c:88: undefined reference to `__imp__glutSwapBuffers@0'
CMakeFiles/glview.dir/glview.c.o: In function `keyPressed': /cygdrive/C/code/libfreenect/examples/glview.c:96: undefined reference to `__imp
etc.

After a git of googling I figured out this because cmake is feading the linker a -lglut flag, when it should be feading it a -lgut32 flag. By manually executing the linking command, I can get the program to build:

/usr/bin/gcc.exe  -Wall -O3 -g  -Wl,--enable-auto-import CMakeFiles/glview.dir/glview.c.o  -o glview.exe -Wl,--out-implib,libglview.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -L/cygdrive/C/code/libfreenect/lib ../lib/libfreenect.a -lGL -lGLU -lglut32 -lm -lpthread -lusb-1.0

But I can't figure out how to get cmake to generate this command for me so no manual steps are needed. Any ideas what I should be doing?

Cheers,

Rob

Upvotes: 0

Views: 893

Answers (1)

stijn
stijn

Reputation: 35901

this is how to add libraries to link to:

target_link_libraries( ${TargetName} gut32 )

find_package only assures the package is found, no more.

Upvotes: 1

Related Questions