完整的CMake Noob。我正在尝试在Clion IDE中使用glfw库,即使经过2天的谷歌搜索,我也无法理解我丢失了什么/做错了。
这里是详细信息:
OS:Windows 8 Pro 64位
IDE:Clion
制作工具:CMake
Complier: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)