将 GLEW 的静态二进制文件与 CMake 链接时未定义对 GLEW 函数的引用
问题
glew32s.lib 未与主可执行文件正确链接。当使用 CMake 给出的 MakeFile 进行构建时,会发生错误,指出我对 glewInit()
有未定义的引用。
CMakeFiles\NoGameEngine.dir/objects.a(window.cpp.obj):window.cpp:(.text+0x15d):对“glewInit”的未定义引用
但是在我的顶级 CMakeLists.txt
我已通过以下方式链接了glew32s.lib:
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
我完全不知道为什么会收到此未定义的引用错误。注意我还声明了编译选项-DGLEW_STATIC
。
我尝试过
使用另一种方式链接库:
target_link_directories( ${PROJECT_NAME} PRIVATE Dependencies)
target_link_libraries( ${PROJECT_NAME} PRIVATE glew32s.lib)
但是我收到以下错误:
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld .exe:跳过不兼容C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib 时 搜索 -lglew32s C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:跳过不兼容C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib 时 搜索 -lglew32s C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:跳过不兼容C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1\glew32s.lib 当 搜索 -lglew32s C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:找不到-lglew32s
资源
CMakeLists.txt:
cmake_minimum_required(VERSION 3.23.)
set(CMAKE_CXX_STANDARD 17)
set(SourceFiles-Core
NoGameEngine-core/src/main.cpp
NoGameEngine-core/src/graphics/window.cpp
)
set(includeFiles-Core NoGameEngine-core/include)
set (includeFiles-Depend Dependencies/include)
add_compile_options(-DGLEW_STATIC)
find_package( OpenGL REQUIRED )
if (OPENGL_FOUND)
MESSAGE("OpenGL Correctly Found")
else (OPENGL_FOUND)
MESSAGE("OpenGL environment missing")
endif()
project(NoGameEngine)
include_directories( ${OPENGL_INCLUDE_DIRS} ${includeFiles-Core} ${includeFiles-Depend})
set( GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_INSTALL OFF CACHE BOOL "GLFW lib only" )
add_subdirectory( Dependencies/GLFW )
add_executable(${PROJECT_NAME} ${SourceFiles-Core})
target_link_libraries( ${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES} glfw)
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
目录层次结构:
根:
- 构建
- 依赖项
- GLFW
- 包括
- GL
- glew32s.lib
- NoGameEngine-核心
- 包括
- 来源
- CMakeLists.txt
Problem
glew32s.lib
is not linking correctly with the main executable. When building with MakeFile given by CMake, an error occurs stating that I have an undefined reference to glewInit()
.
CMakeFiles\NoGameEngine.dir/objects.a(window.cpp.obj):window.cpp:(.text+0x15d): undefined reference to `glewInit'
However in my top-level CMakeLists.txt
I have linked the glew32s.lib
through:
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
I am completely clueless to why I am getting this undefined reference error. Note I have also declared the compile option -DGLEW_STATIC
.
What I have tried
Using another way to link the library:
target_link_directories( ${PROJECT_NAME} PRIVATE Dependencies)
target_link_libraries( ${PROJECT_NAME} PRIVATE glew32s.lib)
However I get the following errors:
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1/glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~4/C__~1/Projects/GAMEPR~1/NOGAME~1/DEPEND~1\glew32s.lib when
searching for -lglew32s
C:/MinGW64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglew32s
Resources
CMakeLists.txt:
cmake_minimum_required(VERSION 3.23.)
set(CMAKE_CXX_STANDARD 17)
set(SourceFiles-Core
NoGameEngine-core/src/main.cpp
NoGameEngine-core/src/graphics/window.cpp
)
set(includeFiles-Core NoGameEngine-core/include)
set (includeFiles-Depend Dependencies/include)
add_compile_options(-DGLEW_STATIC)
find_package( OpenGL REQUIRED )
if (OPENGL_FOUND)
MESSAGE("OpenGL Correctly Found")
else (OPENGL_FOUND)
MESSAGE("OpenGL environment missing")
endif()
project(NoGameEngine)
include_directories( ${OPENGL_INCLUDE_DIRS} ${includeFiles-Core} ${includeFiles-Depend})
set( GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_INSTALL OFF CACHE BOOL "GLFW lib only" )
add_subdirectory( Dependencies/GLFW )
add_executable(${PROJECT_NAME} ${SourceFiles-Core})
target_link_libraries( ${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES} glfw)
target_link_libraries( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Dependencies/glew32s.lib)
Directory Hierarchy:
Root:
- build
- Dependencies
- GLFW
- include
- GL
- glew32s.lib
- NoGameEngine-core
- include
- src
- CMakeLists.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论