在更改为CMake和Travis CI构建环境时,我启用了Travis CI上的编译。即使CMake项目在我的电脑上正确编译,Travis还是退出了2:
In file included from /home/travis/build/Codestones/Proton/source/application.cpp:1:0:
/home/travis/build/Codestones/Proton/source/application.h:3:23: fatal error: glad\glad.h: No such file or directory
#include <glad\glad.h>
^
compilation terminated.
make[2]: *** [CMakeFiles/Proton.dir/source/application.cpp.o] Error 1
make[1]: *** [CMakeFiles/Proton.dir/all] Error 2
make: *** [all] Error 2
这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(Proton)
set(CMAKE_CXX_STANDARD 11)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source")
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies")
# Executable definition and properties
file(GLOB SOURCES
"${SRC_DIR}/*.h"
"${SRC_DIR}/*.cpp"
)
add_executable(Proton "${SOURCES}")
# GLFW
set(GLFW_DIR "${LIB_DIR}/glfw")
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
add_subdirectory("${GLFW_DIR}")
target_link_libraries(${PROJECT_NAME} "glfw" "${GLFW_LIBRARIES}")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLFW_DIR}/include")
target_compile_definitions(${PROJECT_NAME} PRIVATE "GLFW_INCLUDE_NONE")
# GLAD
set(GLAD_DIR "${LIB_DIR}/glad")
add_subdirectory("${GLAD_DIR}")
target_link_libraries(${PROJECT_NAME} "glad" "${GLAD_LIBRARIES}")
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_BINARY_DIR}/dependencies/glad/include")
我认为这意味着glad.h缺失或链接不正确,但为什么它会在我的电脑上构建并运行良好?
答案 0 :(得分:3)
\
不能在#include
指令中用作路径分隔符,请使用/
。如果你的本地(Windows?)编译器理解它,它是一个非可移植的扩展。
答案 1 :(得分:2)
gcc支持Windows上包含路径中的反斜杠作为扩展名
#include <glad\glad.h>
在linux下不支持此功能,您只应在包含路径
中使用正斜杠/
#include <glad/glad.h>