我是C ++和CMake的新手,并开始了一个大项目。我使用VScode作为文本编辑器,使用CMake作为构建工具。
问题在于,我可以在所有具有相同名称但具有 header-only 的源文件的所有头文件中包含“ SFML / Graphics.hpp”如果我包含“ SFML / Graphics.hpp”文件或包含“ SFML / Graphics” cmake的任何其他文件将无法生成并返回错误。
这是我的代码
Game|> (root)
|- CMakeLists.txt
|> include
| |- BaseComponent.hpp (Header-only)
| |- TransformComponent.hpp (Header-only)
| |- CombatComponent.hpp (Header-only)
| |- MovementComponent.hpp (Header-only)
| |- Constants.hpp (Header-only)
| |- TimeUtils.hpp (Header-only)
| |- EcsManager.hpp
| |- EntityManager.hpp
| |- Game.hpp
| |- GameContext.hpp (Header-only)
| |- Scene.hpp (Header-only)
| |- GameScene.hpp
| |- System.hpp
| |- Input.hpp
| |- MovementSystem.hpp
| |- RenderableSystem.hpp
|> src
| |- CMakeLists.txt
| |- main.cpp
| |- Game.cpp
| |- EntityManager.cpp
| |- SceneManager.cpp
| |- Input.cpp
| |- GameScene.cpp
| |> Ecs
| |- CMakeLists.txt
| |- EcsManager.cpp
| |- System.cpp
| |> Systems
| |- CMakeLists.txt
| |- MovementSystem.cpp
| |- RenderableSystem.cpp
|
|> bin
|> build
project(RPG)
set(CMAKE_TOOLCHAIN_FILE
"C:/Users/dante/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin")
set(SOURCES src/EntityManager.cpp src/Game.cpp src/GameScene.cpp
src/main.cpp src/SceneManager.cpp src/Input.cpp)
include_directories("${PROJECT_SOURCE_DIR}/include")
add_subdirectory(src)
find_package(SFML 2.5.1 COMPONENTS REQUIRED graphics window system network
audio)
find_package(nlohmann_json 3.2.0 REQUIRED)
add_executable(RPG ${SOURCES})
target_link_libraries(RPG sfml-graphics sfml-window sfml-system sfml-
network sfml-audio)
target_link_libraries(RPG nlohmann_json::nlohmann_json)
target_link_libraries(RPG ECS)
add_subdirectory(Ecs)
add_subdirectory(Systems)
add_library(ECS EcsManager.cpp System.cpp )
target_link_libraries(ECS ECS_SYSTEMS)
add_library(ECS_SYSTEMS MovementSystem.cpp RenderableSystem.cpp)
Cmake输出的错误是:'SFML / Graphics.hpp':没有这样的文件或目录MSVC(C1083)
如果我在任何“任何”组件类中包含“ SFML / Graphics.hpp”,则会产生错误 如果我在.hpp文件中包含与之关联的.cpp文件的“ SFML / Graphics.hpp”,并将该类包含在“任何”组件类(或任何其他仅标头)中,则会产生错误。
在stackoverflow中找不到任何解决方案。
不要判断我的文件夹结构是在第一次出现错误时有所不同的……而不是我更改为查看CMake是否可以构建。
答案 0 :(得分:0)
您需要将SFML包含目录添加到包含目录列表中。
之后
find_package(SFML 2.5.1 COMPONENTS REQUIRED graphics window system network audio)
添加行
include_directories(${SFML_INCLUDE_DIR})