我有以下基本代码
#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。
发布于 2021-04-08 03:40:05
通过在CMakeLists.txt中添加以下内容解决问题(谢谢@alterigel)
find_package(SFML 2.5 COMPONENTS system window graphics REQUIRED)https://stackoverflow.com/questions/66996951
复制相似问题