[英]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.