严重错误:找不到SFML/System.hpp文件 [英] fatal error: SFML/System.hpp' file not found

查看:608
本文介绍了严重错误:找不到SFML/System.hpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与SMFL,CMAKE和VSCode. Cmake无法链接这些SFML文件.我安装SFML& CMake使用自制软件.

I am trying to work with SMFL, CMAKE & VSCode. Cmake cannot link these SFML files. I install SFML & CMake using Homebrew.

我尝试将SFML文件包含在SMFL_ROOT&中; SFML_INCLUDE_DIR无济于事.

I have tried including the SFML files with SMFL_ROOT & SFML_INCLUDE_DIR to no avail.

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)

我的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

推荐答案

错误在于此行:

target_link_libraries(Main ${SFML_LIBRARIES})

这不会正确传播需求.它只会链接sfml库.通常,您还需要其他要求,例如包含目录.

This won't propagate requirements properly. It will only link the sfml libraries. Usually you also want other requirement such as include directories.

相反,您应该链接到sfml导出的目标:

Instead, you should link to the targets exported by sfml:

target_link_libraries(Main PRIVATE sfml-graphics sfml-system)

您也不需要:

# 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)

这篇关于严重错误:找不到SFML/System.hpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆