简体   繁体   English

多个Cmake文件和SFML“严重错误:SFML / Graphics.hpp:无此类文件或目录”

[英]Multiple Cmake files and SFML “fatal error: SFML/Graphics.hpp: No such file or directory”

I've got 2 CMakeLists.txt files in my project. 我的项目中有2个CMakeLists.txt文件。

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)

core/CMakeLists.txt 核心/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()

And I'm getting this error while compiling "core/ecs/Entity.hpp:3:29: fatal error: SFML/Graphics.hpp: No such file or directory". 而且我在编译“ core / ecs / Entity.hpp:3:29:致命错误:SFML / Graphics.hpp:没有这样的文件或目录”时遇到此错误。 Could someone take a look and tell me what's wrong with this? 有人可以告诉我这是怎么回事吗?

Your script won't work this way, it's most likely broken due to you calling project() more than once. 您的脚本无法以这种方式工作,它很可能由于您多次调用project()而被破坏了。

The stuff inside core is handled as a standalone project, so the include directories etc. inside are never applied to your root. core内部的内容被视为一个独立项目,因此内部的包含目录等永远不会应用于您的根目录。

Remove the first line project(Core) from the second file and define the target directly as Core . 从第二个文件中删除第一行project(Core) ,并将目标直接定义为Core After that it should work, unless I've missed something else. 在那之后它应该可以工作,除非我错过了其他事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:SFML/Graphics.hpp:不存在这样的文件或目录 - Fatal error: SFML/Graphics.hpp: no such file or directory exists 创建新文件时,它显示“ <SFML/Graphics.hpp> 没有相应的文件和目录” - On creation of a new file it shows “<SFML/Graphics.hpp> no such file or directory” 在 VSCode“SFML/Graphics.hpp 没有这样的文件或目录”gcc 中包含 SFML 库 - include SFML Library in VSCode "SFML/Graphics.hpp no such file or directory" gcc 我的项目中的某些仅标头文件不能包含使用 CMake 和 Vscode 的“SFML/Graphics.hpp” - Some headers-only files in my project cannot include “SFML/Graphics.hpp” using CMake and Vscode 包含Graphics.hpp时出现奇怪的错误-SFML - Strange error when including Graphics.hpp - SFML 编译器找不到SFML / Graphics.hpp,但已将其添加到includeirs - Compiler can't find SFML/Graphics.hpp, but it is added to includedirs 致命错误:找不到SFML / System.hpp文件 - fatal error: SFML/System.hpp' file not found SFML创建新文件时: <SFML/Graphics.cpp> 没有这样的目录? - SFML On creation of new file: “<SFML/Graphics.cpp> no such directory”? 无法打开包含文件“Graphics.hpp”没有这样的文件或目录,Visual Studio 的附加包含不起作用 - cannot open include file 'Graphics.hpp' no such file or directory ,additional include for visual studio not working C++ SFML src/Utility/FileSystem.hpp:8:36: 致命错误 - C++ SFML src/Utility/FileSystem.hpp:8:36: fatal error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM