I work on windows with QtCreator .I try to use freeglut/opengl2 all libs have been build and install properly But have undefined references to all glut components certainly due to : Targets may link only to libraries. CMake is dropping the item.
here my CMakelists.txt
project(Projet_AIN CXX)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED)
include_directories(${GLEW_INCLUDE_DIR}
${GLUT_INCLUDE_DIR}
${OpenGL_INCLUDE_DIR})
link_directories(${GLEW_LIBRARIES_DIR}
${GLUT_LIBRARY_DIR}
${OpenGL_LIBRARY_DIR})
add_definitions(${OpenGL_DEFINITIONS}
${GLEW_DEFINITIONS}
${GLUT_DEFINITIONS})
set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
file(
GLOB
SOURCE_FILES
include/*.hpp
src/*.cpp
)
add_executable(
${PROJECT_NAME}
${SOURCE_FILES}
)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${GLEW_LIBRARY}
${GLUT_LIBRARY}
)
CMake output:
Running "C:\cmake\bin\cmake.exe C:/Users/Thibaut/Documents/Projet_Raffin "-GCodeBlocks - MinGW Makefiles" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_CXX_COMPILER:STRING=C:/MinGW/bin/g++.exe" "-DCMAKE_C_COMPILER:STRING=C:/MinGW/bin/gcc.exe" "-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}" "-DGLEW_INCLUDE_DIR:PATH=C:/Program Files (x86)/glew/include" "-DGLEW_LIBRARY:FILEPATH=C:/Program Files (x86)/glew/lib" "-DGLUT_INCLUDE_DIR:PATH=C:/Program Files (x86)/freeglut/include" "-DGLUT_glut_LIBRARY:FILEPATH=C:/Program Files (x86)/freeglut/lib" "-DQT_QMAKE_EXECUTABLE:STRING="" in C:\Users\Thibaut\Documents\build-Projet_Raffin-Kat-Debug.
-- Configuring done
WARNING: Target "Projet_AIN" requests linking to directory "C:/Program Files (x86)/glew/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "Projet_AIN" requests linking to directory "C:/Program Files (x86)/freeglut/lib". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: C:/Users/Thibaut/Documents/build-Projet_Raffin-Kat-Debug
Make output:
14:26:39: Exécution des étapes pour le projet Projet_AIN...
14:26:39: Running CMake in preparation to build...
14:26:39: Débute : "C:\cmake\bin\cmake.exe" --build . --target all
[ 50%] Building CXX object CMakeFiles/Projet_AIN.dir/src/main.cpp.obj
[100%] Linking CXX executable bin\Debug\Projet_AIN.exe
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `glutInit_ATEXIT_HACK':
C:/PROGRA~2/freeglut/include/GL/freeglut_std.h:637: undefined reference to `__imp___glutInitWithExit'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `glutCreateWindow_ATEXIT_HACK':
C:/PROGRA~2/freeglut/include/GL/freeglut_std.h:639: undefined reference to `__imp___glutCreateWindowWithExit'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `glutCreateMenu_ATEXIT_HACK':
C:/PROGRA~2/freeglut/include/GL/freeglut_std.h:641: undefined reference to `__imp___glutCreateMenuWithExit'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `action_timer(int)':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:30: undefined reference to `__imp_glutPostRedisplay'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:31: undefined reference to `__imp_glutTimerFunc'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `RenderScene()':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:71: undefined reference to `__imp_glutWireTeapot'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:73: undefined reference to `__imp_glutSwapBuffers'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `callback_Keyboard(unsigned char, int, int)':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:80: undefined reference to `__imp_glutLeaveMainLoop'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `InitializeGL()':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:113: undefined reference to `__imp_glutTimerFunc'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `GlewInit()':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:118: undefined reference to `__imp_glewInit'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:122: undefined reference to `__imp_glewGetErrorString'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:125: undefined reference to `__imp_glewGetString'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:127: undefined reference to `__imp_glewIsSupported'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `InitializeGlutCallbacks':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:141: undefined reference to `__imp_glutDisplayFunc'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:148: undefined reference to `__imp_glutKeyboardFunc'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:154: undefined reference to `__imp_glutReshapeFunc'
CMakeFiles\Projet_AIN.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:167: undefined reference to `__imp_glutInitDisplayMode'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:169: undefined reference to `__imp_glutInitWindowPosition'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:170: undefined reference to `__imp_glutInitWindowSize'
C:/Users/Thibaut/Documents/Projet_Raffin/src/main.cpp:182: undefined reference to `__imp_glutMainLoop'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\Projet_AIN.dir\build.make:97: bin/Debug/Projet_AIN.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/Projet_AIN.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
14:26:42: Le processus "C:\cmake\bin\cmake.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet Projet_AIN (kit : Kat)
When executing step "Make"
Fundamentally, to get rid of Targets may link only to libraries.CMake is dropping the item.
error, you need to try linking only the path to lib and not the lib directory
For instance:
This error happens if you specify:
FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release
You need to specify path to the .lib:
FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release\freetype.lib
Thanks to Link