SFML community forums

Help => General => Topic started by: carton83 on November 15, 2013, 09:03:03 pm

Title: [Debian Linux]I'm getting some odd errors when trying to compile
Post by: carton83 on November 15, 2013, 09:03:03 pm
This is my code

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(400, 400), "Test!");
    window.setFramerateLimit(4);
    sf::Event event;

    while(window.isOpen())
    {
        while(window.pollEvent(event));
        {
            switch (event.type)
            {
            case sf::Event::Closed:
                window.close();
                break;
            default:
                window.clear(sf::Color(134,0,0));
                window.display();
            }
        }
    }
    window.close();
    return 0;
}

If I run

g++ -o -v main.cpp -lsfml-graphics

and I get

/usr/bin/ld: /tmp/ccduJuDb.o: undefined reference to symbol '_ZN2sf6Window17setFramerateLimitEj'
/usr/lib/libsfml-window.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

But if I run

g++ -o main.cpp -lsfml-graphics

I get this (http://bpaste.net/raw/JJtASBm2eVRPa0PYQD8O/) and my main.cpp file is deleted.

What am I doing wrong?

Oh, and I just try compiling in Code Blocks, I get a bunch of undefined reference errors.
Title: Re: [Debian Linux]I'm getting some odd errors when trying to compile
Post by: Jebbs on November 15, 2013, 09:29:48 pm
Don't forget that you also need to link to the modules that certain modules rely on. If you link to sfml-graphics, you also need to link to sfml-window and sfml-system.
Title: Re: [Debian Linux]I'm getting some odd errors when trying to compile
Post by: lockandstrike on November 15, 2013, 11:42:00 pm
It's also important that you link them in the correct order. Like so:

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