gpt4 book ai didi

c++ - 多个 Cmake 文件和 SFML "fatal error: SFML/Graphics.hpp: No such file or directory"

转载 作者:行者123 更新时间:2023-12-02 10:59:20 27 4
gpt4 key购买 nike

我的项目中有 2 个 CMakeLists.txt 文件。

CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(Game)

set(CMAKE_CXX_STANDARD 14)

include_directories(core)
add_subdirectory(core)

add_executable(${PROJECT_NAME} game/main.cpp)
target_link_libraries(${PROJECT_NAME} Core)

核心/CMakeLists.txt
project(Core)    
set(SOURCE_FILES ecs/Component.hpp ecs/Destroyable.hpp ecs/Destroyable.cpp ecs/Entity.hpp ecs/Entity.cpp Game.cpp Game.hpp components/Sprite.hpp components/Sprite.cpp components/Transform.hpp components/Transform.cpp ecs/Serializable.hpp ecs/ComponentsCreator.cpp ecs/ComponentsCreator.hpp common/Utility.cpp common/Utility.hpp common/Logger.hpp common/Logger.cpp common/Vector2.hpp common/Vector2.cpp components/Camera.cpp components/Camera.hpp ecs/Component.cpp components/AnimationPlayer.cpp components/AnimationPlayer.hpp Animation.cpp Animation.hpp Frame.cpp Frame.hpp lib/termcolor.hpp lib/json.hpp)

add_library(${PROJECT_NAME} ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()

我在编译“core/ecs/Entity.hpp:3:29: fatal error: SFML/Graphics.hpp: No such file or directory”时遇到了这个错误。有人可以看看并告诉我这有什么问题吗?

最佳答案

你的脚本不能这样工作,很可能是因为你调用了project()不止一次。

里面的东西core被作为一个独立的项目处理,所以里面的包含目录等永远不会应用于你的根目录。

删除第一行 project(Core)从第二个文件中直接定义目标为Core .之后它应该可以工作,除非我错过了其他东西。

关于c++ - 多个 Cmake 文件和 SFML "fatal error: SFML/Graphics.hpp: No such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48137077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com