SFML 2.1 RenderWindow linking error

左心房为你撑大大i 提交于 2019-12-11 08:25:55

问题


My code:

#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; 
}

My compiler call:

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

The error message:

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

Is RenderWindow in a library I forgot to link? I assumed it was in the 'window' one.. I'm running SFML 2.1 and tried various linking combinations, all of which give me linking errors. This linking chain is the one that gives me the least error, namely the RenderWindow error. Someone help me figure this out? I'm at a bit of a loss here. I'm running on mac os 10.8.


回答1:


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

It's in the graphics package. Hence in sfml-graphics. But you already linked that one. However, you're not suppose to link against SFML.framework (it contains only header files).

As stated here, you can use either frameworks or dylibs. Your program can be compiled with either:

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

or

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

Now, regarding the Undefined symbols for architecture x86_64 error, I can only guess you didn't download the compatible version from the download page. If you want to use g++, download the "GCC" version.

Or, switch to clang. (E.g., you can see here that clang can be faster than GCC.)



来源:https://stackoverflow.com/questions/17910387/sfml-2-1-renderwindow-linking-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!