GL / glew.h:glew.c中没有这样的文件或目录

问题描述

当我尝试编译程序时,出现此错误

C:\...\CLionProjects\Radix\vendors\glew-2.1.0\src\glew.c:34:10: fatal error: GL/glew.h: No such file or directory
 #include <GL/glew.h>
          ^~~~~~~~~~~

错误在库代码中,我在这里做什么错了?

我的项目结构如下:

Radix
|- Radix-core
   |- cpp code..
|- vendors
   |- CMakeLists.txt
   |- glew-2.1.0
   |- Other libs..
- CMakeLists.txt

CMakeLists.txt(只是一些问题)

add_subdirectory(vendors)

add_definitions(-DTW_STATIC -DTW_NO_LIB_PRAGMA -DTW_NO_DIRECT3D -DGLEW_STATIC -D_CRT_SECURE_NO_WARNINGS)

# Including GLEW
include_directories(vendors/glew-2.1.0/include)
set(ALL_LIBS opengl32 glfw GLEW_210)

target_link_libraries(Radix ${ALL_LIBS})

vendors / CMakeLists.txt(只是出现问题的部分)

add_definitions(-DTW_STATIC -DTW_NO_LIB_PRAGMA -DTW_NO_DIRECT3D -DGLEW_STATIC -D_CRT_SECURE_NO_WARNINGS)

### GLEW ###
set(GLEW_HEADERS)
set(GLEW_SOURCE glew-2.1.0/src/glew.c)
set(GLEW_INCLUDE glew-2.1.0/include)

add_library(GLEW_210 ${GLEW_SOURCE} ${GLEW_INCLUDE})
target_link_libraries(GLEW_210 ${OPENGL_LIBRARY} ${EXTRA_LIBS})

解决方法

将包含目录添加到GLEW_210的源文件中不会执行任何操作。而是将其添加为PUBLIC包含目录,因此glew.c的编译也可以访问glew标头:

target_include_directories(GLEW_210 PUBLIC glew-2.1.0/include)

这还会将include目录传播到与GLEW_210链接的任何目标,因此您可以在主CMakeLists.txt中删除include_directories语句

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...