sfml 不再编译

sfml does not compile anymore

我有以下基本代码

#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;

int main() {
    sf::ContextSettings settings;
    settings.antialiasingLevel = 8;
    sf::RenderWindow window(sf::VideoMode(800, 600), "PONG", sf::Style::Default,
                            settings);

    sf::Clock clock;

    sf::Time elapsedTime;

    srand(time(0));
    while (window.isOpen()) {
        elapsedTime = clock.getElapsedTime();
        clock.restart();

        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) window.close();
        }

        // clear window
        window.clear(sf::Color::Black);

        window.display();
    }
}

当我尝试编译它时,出现以下错误

/usr/bin/ld: CMakeFiles/sfml-astar.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x12c): undefined reference to `sf::WindowBase::isOpen() const'
/usr/bin/ld: main.cpp:(.text+0x172): undefined reference to `sf::WindowBase::pollEvent(sf::Event&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/sfml-astar.dir/build.make:104: sfml-astar] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/sfml-astar.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

我的 CmakeLists.txt 看起来像这样:

cmake_minimum_required(VERSION 3.5)

project(sfml-astar LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(sfml-astar main.cpp)

target_link_libraries(sfml-astar sfml-graphics sfml-system sfml-window)

此代码在 12 小时前很好编译。我重新安装了一次 SFML,但没有解决问题。我是 运行 arch linux.

通过将以下内容添加到 CMakeLists.txt 解决(感谢@alterigel)

find_package(SFML 2.5 COMPONENTS system window graphics REQUIRED)