没有这样的文件或目录,而本地构建工作正常

No such file or directory while local build works fine

本文关键字:构建 工作 文件      更新时间:2023-10-16

在更改为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: gladglad.h: No such file or directory
 #include <gladglad.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

这是我的CMakeList.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 丢失或链接不正确,但为什么它会在我的电脑上构建和运行良好?

不能用作#include指令中的路径分隔符,请使用/ 。如果你的本地(Windows?(编译器理解它,它是一个不可移植的扩展。

gcc 支持在 Windows 上的包含路径中使用反斜杠作为扩展

#include <gladglad.h>

这在 linux 下不受支持,您应该只在包含路径中使用正斜杠/

#include <glad/glad.h>