CMake 正在删除项目 c

新手上路,请多包涵

我使用 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}
                  )

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

制作输出:

 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"

原文由 Otha 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 710
1 个回答

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

例如:

如果您指定:

 FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release

您需要指定 .lib 的路径:

 FREETYPE_LIBRARY_REL = H:\OgreSDK_vc9_v1-7-1\lib\release\freetype.lib

感谢 链接

原文由 Anvesh Yalamarthy 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题