如何在CLion中运行SFML,错误未定义引用?

 曾经 发布于 2022-12-15 10:01

我是C++的新手并且尝试学习游戏编程,我选择SFML并使用Jetbrain在CLion上运行并使用Ubuntu机器.我在这里学习SFML和Linux这个教程 我的代码:

#include 

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

如何配置使用所有引用变量而不是每次都在终端手动?谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有