[英]fatal error: SFML/System.hpp' file not found
I am trying to work with SMFL, CMAKE & VSCode. 我正在尝试使用SMFL,CMAKE和VSCode。 Cmake cannot link these SFML files.
Cmake无法链接这些SFML文件。 I install SFML & CMake using Homebrew.
我使用Homebrew安装SFML和CMake。
I have tried including the SFML files with SMFL_ROOT
& SFML_INCLUDE_DIR
to no avail. 我试过将
SMFL_ROOT
和SFML_INCLUDE_DIR
包含在SFML文件中。
cmake_minimum_required(VERSION 3.14.2)
project(WordTypeCpp VERSION 0.1.0 )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 17)
find_package(SFML REQUIRED COMPONENTS graphics system)
if (SFML_FOUND)
set(SFML_ROOT "/usr/local/Cellar/sfml/2.5.1/include/SFML/")
# include_directories(${SFML_INCLUDE_DIR} "/usr/local/Cellar/sfml/2.5.1/include")
endif(SFML_FOUND)
set(SOURCE_FILES Main.cpp)
add_executable(Main ${SOURCE_FILES})
target_link_libraries(Main ${SFML_LIBRARIES})
add_definitions(-include ${CMAKE_CURRENT_SOURCE_DIR}/PCH.hpp)
include(CPack)
My Main.cpp
file 我的
Main.cpp
文件
#include "PCH.hpp"
#include "Main.hpp"
int main()
{
std::cout << "SFML is running!" << '\n';
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
#ifdef SFML_SYSTEM_WINDOWS
__windowsHelper.setIcon(window.getSystemHandle());
#endif
sf::CircleShape shape(window.getSize().x / 2);
shape.setFillColor(sf::Color::White);
sf::Texture shapeTexture;
shapeTexture.loadFromFile("content/sfml.png");
shape.setTexture(&shapeTexture);
sf::Event event;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
// PCH.hpp file
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
--config Debug --target Main -- -j 6
[build] [1/2 50% :: 1.825] Building CXX object src/CMakeFiles/Main.dir/Main.cpp.o
[build] FAILED: src/CMakeFiles/Main.dir/Main.cpp.o
[build] /usr/bin/clang++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -include /Users/.../WordTypeCpp/src/PCH.hpp -std=gnu++1z -MD -MT src/CMakeFiles/Main.dir/Main.cpp.o -MF src/CMakeFiles/Main.dir/Main.cpp.o.d -o src/CMakeFiles/Main.dir/Main.cpp.o -c ../src/Main.cpp
[build] In file included from <built-in>:1:
[build] /Users/.../WordTypeCpp/src/PCH.hpp:11:10: fatal error: 'SFML/System.hpp' file not found
[build] #include <SFML/System.hpp>
[build] ^~~~~~~~~~~~~~~~~
[build] 1 error generated.
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
The error lies on this line: 错误在于此行:
target_link_libraries(Main ${SFML_LIBRARIES})
This won't propagate requirements properly. 这不会正确传播需求。 It will only link the sfml libraries.
它只会链接sfml库。 Usually you also want other requirement such as include directories.
通常,您还需要其他要求,例如包含目录。
Instead, you should link to the targets exported by sfml: 相反,您应该链接到sfml导出的目标:
target_link_libraries(Main PRIVATE sfml-graphics sfml-system)
Also you shouldn't need that: 另外,您不需要:
# uneeded
if (SFML_FOUND)
set(SFML_ROOT "/usr/local/Cellar/sfml/2.5.1/include/SFML/")
# include_directories(${SFML_INCLUDE_DIR} "/usr/local/Cellar/sfml/2.5.1/include")
endif(SFML_FOUND)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.