问题描述
我是C ++的新手,尝试学习游戏编程,我选择SFML,然后由Jetbrain在CLion上运行,并使用Ubuntu计算机。我按照本教程此处输入我的代码:
I'm new to C++ and try to learn game programming, I choose SFML and run on CLion by Jetbrain and using Ubuntu machine. I following this tutorial SFML and Linux here my code :
#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上运行时出错
When I run on CLion it error
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可以做什么那?我只通过终端运行,如果运行此命令,它将起作用。
How I config or setup to run SFML in CLion, I don't know CMAKE can do that? I only run by terminal, It work if I run this command.
g++ -c main.cpp
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
./sfml-app
如何配置以使用所有引用变量,而无需每次在Terminal中手动进行操作?谢谢。
How to config to use all reference variable without do manual every time in Terminal? Thanks.
推荐答案
您需要在CMakeLists.txt中链接SFML库。
You need to link SFML library in your CMakeLists.txt.
查看CMake 。
然后可能有助于您了解如何在CMake中找到SFML库路径。
And this link may be helpful for you to know how to find SFML library path in CMake.
这是FindSFML.cmake模块:
Here is a FindSFML.cmake module: https://github.com/LaurentGomila/SFML/blob/master/cmake/Modules/FindSFML.cmake
这篇关于如何在CLion中运行SFML,错误未定义引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!