我刚接触C++并想学习游戏编程,我选择了SFML,并在Jetbrain的CLion上使用Ubuntu机器运行。我正在遵循这个教程SFML and Linux,这是我的代码:
#include <SFML/Graphics.hpp>
using namespace sf;
int main() {
RenderWindow window(sf::VideoMode(200, 200), "SFML Work!");
CircleShape shape(100.f);
shape.setFillColor(Color::Green);
while (window.isOpen()) {
Event event;
while (window.pollEvent(event)) {
if (event.type == Event::Closed) {
window.close();
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
当我在CLion上运行时出现错误
CMakeFiles/SFMLBasic.dir/main.cpp.o: In function `main':
undefined reference to `sf::String::String(char const*, std::locale const&)'
undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
...
undefined reference to `sf::Shape::~Shape()'
我该怎样在CLion中配置或安装SFML?我不知道CMAKE是否能做到这一点?我只能通过终端运行,如果我运行这个命令,它就可以工作。
g++ -c main.cpp
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
./sfml-app
如何配置才能在终端中使用所有引用变量,而不需要手动操作?谢谢。
${SFML_DEPENDENCIES}
。在链接共享库时不会产生任何问题,并且在切换到静态链接时会自动添加所有SFML的依赖项。 - Lukas