【问题标题】:My SFML (in CodeBlocks) doesn't work我的 SFML(在 CodeBlocks 中)不起作用
【发布时间】:2016-05-03 17:52:05
【问题描述】:

这段代码有问题:

#include <SFML/Graphics.hpp>


int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

当我尝试运行它时,CodeBlocks 说:

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&)

还有很多其他错误。这里的库包括

我也定义了“SFML_STATIC”。 有谁知道为什么?谢谢。

【问题讨论】:

  • 你能发布“很多其他错误”吗?有人可能会解释为什么会出现这些错误。

标签: c++ sfml


【解决方案1】:

从 SFML 2.2 开始,静态链接时,您必须链接所有 SFML 对您的项目的依赖关系。这意味着如果你 例如,正在链接 sfml-window-s 或 sfml-window-s-d,您将 还必须链接opengl32、winmm和gdi32。其中一些依赖 库可能已经在“继承的值”下列出,但添加 他们自己再一次应该不会造成任何问题。

此外,因为 Code::Blocks 使用 GCC,所以链接顺序很重要。 这意味着依赖于其他库的库必须是 在它们所依赖的库之前添加到库列表中。如果你 不遵守这条规则,你会得到链接器错误。

你可以在这里看到每个模块的依赖关系

http://www.sfml-dev.org/tutorials/2.3/start-cb.php

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多