SFML 2.1 RenderWindow链接错误

时间:2013-07-28 16:35:05

标签: c++ compiler-construction linker sfml

我的代码:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    while(window.isOpen())
    {
        sf::Event Event; 
        while(window.pollEvent(Event))
        {
            if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
                window.close();
        }

        window.display();
    }
    return 0; 
}

我的编译器调用:

g++ main.cpp -framework SFML -lsfml-graphics -lsfml-window -lsfml-system

错误消息:

Undefined symbols for architecture x86_64:
      "sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in cc8BMfpR.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

RenderWindow是否在我忘记链接的库中?我假设它在'窗口'中。我正在运行SFML 2.1并尝试了各种链接组合,所有这些都给了我链接错误。这个链接链是给我最小错误的链,即RenderWindow错误。有人帮我搞清楚了吗?我在这里有点不知所措。我在mac os 10.8上运行。

1 个答案:

答案 0 :(得分:1)

  

RenderWindow是否在我忘记链接的库中?我以为它是在'窗口'一个..

它在图形包中。因此在sfml-graphics中。但是你已经把那个联系起来。但是,您不应该链接SFML.framework(它只包含头文件)。

如上所述here,您可以使用框架或dylib。您的程序可以使用以下任一方式编译:

g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system

g++ main.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system

现在,关于架构x86_64的未定义符号错误,我只能猜测你没有从download page下载兼容版本。如果要使用g ++,请下载“GCC”版本。

或者,切换到clang。 (例如,你可以看到here clang可能比GCC更快。)

相关问题