问题描述
在这里完成CMake Noob.我正在尝试在Clion IDE中使用glfw库,即使经过2天的谷歌搜索,我也无法理解我丢失/做错了什么.
complete CMake Noob here. I am trying to use glfw library in Clion IDE and even after 2 days of googling, i cannot understand what am i missing/doing wrong.
以下是详细信息:
操作系统:Windows 8 Pro 64bit
OS: Windows 8 Pro 64bit
IDE:Clion
IDE: Clion
制作工具:CMake
Make tool: CMake
编译器:MinGW v3.21
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
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)
推荐答案
这就是我解决头痛的方法:
This is how i fixed this headache:
-
下载了32位的glfw二进制文件(即使我使用的是64位计算机)
Downloaded 32 bit of glfw binaries (even though i am on 64 bit machine)
重命名并复制我项目中二进制文件中粘贴的所选文件,如下所示:
Renamed and Copy pasted selected files from the binaries in my project like this:
像这样修改了我的CMakeLists.txt:
modified my CMakeLists.txt like this:
- 构建并点击运行!
这篇关于GLFW + CMake + Clion许多未定义的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!