CMake正在删除项目C ++

Oth*_*tha 6 c++ cmake freeglut

我使用QtCreator在Windows上工作。我尝试使用freeglut / opengl2正确构建并安装了所有库,但是由于以下原因,对所有glut组件的引用均未定义:目标只能链接到库。CMake正在删除该项目。

这是我的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}
                  )
Run Code Online (Sandbox Code Playgroud)

CMake输出:

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
Run Code Online (Sandbox Code Playgroud)

输出:

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"
Run Code Online (Sandbox Code Playgroud)

Anv*_*thy 5

从根本上说,要摆脱Targets may link only to libraries.CMake is dropping the item.错误,您需要尝试仅将路径链接到 lib 而不是 lib 目录

例如:

如果您指定,则会发生此错误:

FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release
Run Code Online (Sandbox Code Playgroud)

您需要指定 .lib 的路径:

FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release\freetype.lib 
Run Code Online (Sandbox Code Playgroud)

感谢链接


Tsy*_*rev 1

脚本的现代方式(由 调用find_package(XXX))将包含变量的库命名为XXX_LIBRARIES

至于XXX_LIBRARY变量,它有时指的是相同的(库列表),或者指的是包含库的目录。看起来第二种情况是你的,这就是你收到该错误的原因。

如果您想知道由 设置的变量的名称find_package(XXX),请参阅该问题