【发布时间】:2016-01-18 13:49:39
【问题描述】:
在此处完成 CMake Noob。我正在尝试在 Clion IDE 中使用 glfw 库,即使经过 2 天的谷歌搜索,我也无法理解我错过了什么/做错了什么。
以下是详细信息:
操作系统:Windows 8 Pro 64 位
IDE:克莱恩
制作工具:CMake
编译器:MinGW v3.21
错误日志:
"C:\Program Files (x86)\JetBrains\CLion 1.2.3\bin\cmake\bin\cmake.exe"--build C:\Users\PranayKarani\.CLion12\system\cmake\generated\185d1d8\185d1d8\Debug --target openGL -- -j 4
[ 50%] Linking CXX executable openGL.exe
CMakeFiles\openGL.dir/objects.a(main.cpp.obj): In function `key_callback':
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:15: undefined reference to `glfwSetWindowShouldClose'
CMakeFiles\openGL.dir/objects.a(main.cpp.obj): In function `main':
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:22: undefined reference to `glfwSetErrorCallback'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:24: undefined reference to `glfwInit'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:27: undefined reference to `glfwCreateWindow'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:30: undefined reference to `glfwTerminate'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:34: undefined reference to `glfwMakeContextCurrent'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:35: undefined reference to `glfwSwapInterval'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:37: undefined reference to `glfwSetKeyCallback'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:44: undefined reference to `glfwGetFramebufferSize'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:47: undefined reference to `_imp__glViewport@16'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:48: undefined reference to `_imp__glClear@4'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:50: undefined reference to `_imp__glMatrixMode@4'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:51: undefined reference to `_imp__glLoadIdentity@0'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:52: undefined reference to `_imp__glOrtho@48'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:53: undefined reference to `_imp__glMatrixMode@4'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:55: undefined reference to `_imp__glLoadIdentity@0'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:56: undefined reference to `glfwGetTime'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:56: undefined reference to `_imp__glRotatef@16'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:58: undefined reference to `_imp__glBegin@4'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:59: undefined reference to `_imp__glColor3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:60: undefined reference to `_imp__glVertex3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:61: undefined reference to `_imp__glColor3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:62: undefined reference to `_imp__glVertex3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:63: undefined reference to `_imp__glColor3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:64: undefined reference to `_imp__glVertex3f@12'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:65: undefined reference to `_imp__glEnd@0'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:67: undefined reference to `glfwSwapBuffers'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:68: undefined reference to `glfwPollEvents'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:39: undefined reference to `glfwWindowShouldClose'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:71: undefined reference to `glfwDestroyWindow'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:73: undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\openGL.dir\build.make:97: recipe for target 'openGL.exe' failed
mingw32-make.exe[3]: *** [openGL.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/openGL.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/openGL.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/openGL.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/openGL.dir/rule] Error 2
Makefile:117: recipe for target 'openGL' failed
mingw32-make.exe: *** [openGL] Error 2
项目结构:
CMakeList.txt
cmake_minimum_required(VERSION 3.3)
project(openGL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(openGL ${SOURCE_FILES})
#add_library(A SHARED IMPORTED)
#set_property(TARGET A PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/GLFW/lib-mingw-w64/glfw3.dll)
add_library(B STATIC IMPORTED)
set_property(TARGET B PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/GLFW/lib-mingw-w64/glfw3dll.a)
add_library(C STATIC IMPORTED)
set_property(TARGET C PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/GLFW/lib-mingw-w64/libglfw3.a)
target_link_libraries(openGL B C)
【问题讨论】:
-
您正在尝试与处于构建状态的
GLFW库链接(因为您的GLFW子目录下有Makefile文件)。那里的文件处于某种 中间 状态,您无法猜出它们的正确用法。相反,您应该在某处安装 GLFW 库,然后链接已安装的文件。查找已安装包文件的最常用方法是find_package。顺便说一句,任何关于 cmake 和 GL 的教程都会显示find_package的用法。 -
我的 CmakeLists.txt 不在 GLFW 目录下