gpt4 book ai didi

c++ - Glew 未定义引用链接错误

转载 作者:行者123 更新时间:2023-11-28 06:15:14 28 4
gpt4 key购买 nike

当我尝试在 CLion 中构建我的项目时,我遇到了来自 cmake 的链接错误。我已经尝试过其他线程所说的:将 opengl 放在最后,将 glu 放在第一位,更改我的 include 的顺序并设置 cmake 选项 GLEW_STATIC 但他们都没有修复它甚至给出不同的错误。

我使用了专门为 mingw32 编译的 glew(来自 https://julianibarz.wordpress.com/2010/05/12/glew-1-5-4-mingw32/ )并且我自己编译了 GLEW 但我仍然遇到同样的问题..

这是我的 CMake 文件:

cmake_minimum_required(VERSION 3.2)
project(3D_prototyping)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package (OpenGL REQUIRED)

if (WIN32)
else (WIN32)
find_package (glfw3 REQUIRED)
endif (WIN32)

set(SOURCE_FILES main.cpp)

add_executable(3D_prototyping ${SOURCE_FILES})
target_link_libraries (3D_prototyping
${GLFW3_LIBRARY}
${OPENGL_LIBRARIES}
${GLEW_LIBRARY}
${COCOA_LIBRARY} ${COREVID_LIBRARY} ${IOKIT_LIBRARY})
if (WIN32)
target_link_libraries (3D_prototyping
${OPENGL_LIBRARIES} glfw3 glu32 opengl32)
endif (WIN32)

这是我遇到的错误:

"C:\Program Files (x86)\JetBrains\CLion 1.0.3\bin\cmake\bin\cmake.exe" --build C:\Users\Max\.clion10\system\cmake\generated\1d24224\1d24224\Debug --target 3D_prototyping -- -j 4
Linking CXX executable 3D_prototyping.exe
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `Z9getShaderPKcj':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:27: undefined reference to `_imp____glewCreateShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:30: undefined reference to `_imp____glewShaderSource'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:31: undefined reference to `_imp____glewCompileShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:35: undefined reference to `_imp____glewGetShaderiv'
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:75: undefined reference to `_imp____glewCreateProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:76: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:77: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:78: undefined reference to `_imp____glewBindFragDataLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:79: undefined reference to `_imp____glewLinkProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:80: undefined reference to `_imp____glewUseProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:83: undefined reference to `_imp____glewGetAttribLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:84: undefined reference to `_imp____glewVertexAttribPointer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:85: undefined reference to `_imp____glewEnableVertexAttribArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:89: undefined reference to `_imp____glewGenVertexArrays'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:90: undefined reference to `_imp____glewBindVertexArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:101: undefined reference to `_imp____glewGenBuffers'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:102: undefined reference to `_imp____glewBindBuffer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:103: undefined reference to `_imp____glewBufferData'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [3D_prototyping.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/3D_prototyping.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/3D_prototyping.dir/rule] Error 2
mingw32-make.exe: *** [3D_prototyping] Error 2
CMakeFiles\3D_prototyping.dir\build.make:86: recipe for target '3D_prototyping.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/3D_prototyping.dir/all' failed
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/3D_prototyping.dir/rule' failed
Makefile:108: recipe for target '3D_prototyping' failed

最佳答案

已修复。

在某个地方,我得到了 glew 使用的 glu32,而不是我编译的 Windows 版本。添加了对 glew32 的引用,它工作正常。

关于c++ - Glew 未定义引用链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30446160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com