c++ - SFML 2.1 RenderWindow 链接错误

标签 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 上运行。

最佳答案

Is RenderWindow in a library I forgot to link? I assumed it was in the 'window' one..

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

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

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

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

现在,关于Undefined symbols for architecture x86_64 错误,我只能猜测您没有从download page 下载兼容版本。 .如果您想使用 g++,请下载“GCC”版本。

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

关于c++ - SFML 2.1 RenderWindow 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17910387/

相关文章:

c++ - 覆盖虚拟成员函数时,为什么覆盖函数总是变为虚拟?

compiler-construction - 为什么需要虚拟机?

r - 自定义包编译选项 R

c++ - 警告 : linker path does not have real file for library -lpthread

c++ - OpenGL 中的简单纹理

c++ - 使用 AVX 模拟 32 字节的移位

c++ - lib 中已经定义了标准库,导致链接器错误

linux - RHEL 6.0 上的链接错误 : using gcc 4. 5.2 -- 我不明白

c++ - 如何用 C++ 计算一个简单句子中的单词和数字

python - PLY - 返回多个 token