Setting up the SFML 2 Release candidate

Posted by Astryl on Jan. 31, 2013, 3:45 a.m.

Copy-pasted from here.

Anybody who has been spying on me thanks to Twitter, Facebook or whatever other communistsocialist media sites I happen to be on might have seen something I posted about accidentally deleting my SFML folder…

So I used this unfortunate accident as a convenient excuse to go and install the SFML 2 RC, and figure out how it works. So here's an overview:

Begin of copy-pasta

Note that this is specifically for setting up the library using Code::Blocks and MinGW. Should translate to the Linux version of CB quite easily.

First things first:http://www.sfml-dev.org/download.php#2.0-rc

Unzip it somewhere sensible. I use C:\Dev\SFML-2.0-rc

Now open Code::Blocks. There are two ways to use the library. Either you can make a project template, or you can change the global compiler path and allow it to use the SFML library at all times. I do the latter.

The process for doing it on a per-project basis simple requires one to use the Project->Build Options menu instead of the Settings->Compiler and Debugger menu.

Anyway, open Settings->Compiler and Debugger. On this page, we want the Search Directories tab, Compiler sub-tab. Here, click on Add, and locate the include directory in the SFML-2.0-rc folder.

Then, switch to the Linker sub-tab, hit Add again, and point it to the lib folder.

Your compiler can now 'see' the SFML headers.

Linking to the SFML library

The names of the libraries haven't changed, but here's a basic configuration I use. In the Project->Build Options->Linker tab, in the Linker Options text box, I usually place the following:

[i]-lsfml-graphics[/i]
[i]-lsfml-window[/i]
[i]-lsfml-system[/i]
[i]-lsfml-main<br />[/i]

Static libraries don't seem to be working right now, for some reason or other, so you'll have to make do with the DLLs. Make sure to move them to the directory your program resides in. Otherwise, it all seems to be plain ol' SFML…

… Or not.

Here's a snippet of code from a bare-bones 'blank window' test I just coded:

// SFML 2 test

#include &lt;SFML/Graphics.hpp>
#include &lt;SFML/Window.hpp>
#include &lt;SFML/System.hpp>

int main(int argc, char** argv)
{
    sf::RenderWindow app(sf::VideoMode(640,480,32),"SFML 2 Test Window");
    app.setFramerateLimit(60);

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

        app.clear();
        app.display();
    }
    return 0;
}

Note the subtle differences. Also, the RenderWindow class has some nice additions to it, and I noticed the addition of a RenderTexture class. I can see these all becoming very useful in my future work.

End of copy-pasta

One + for 64Digits. Our blog editor is better than Tumblr's. It keeps adding in <p> tags whenever it feels like it, forcing me to use the HTML editor. Not that I'll complain too much; I needed to use the HTML editor regardless. Can't format my code otherwise.

Anyway, I promise a potentially interesting blog next time. Unless I forget.

Comments

Astryl 11 years, 7 months ago

Just solved it. Add SFML_STATIC to your #defines in the project settings, and link the static libraries.

Alternatively, add the line #define SFML_STATIC at the top of your main source file before including any of the SFML libraries.

Astryl 11 years, 7 months ago

And you're linking to the s versions of the libraries… Maybe show me a screenshot/dump of the errors you get when trying to link statically? Seems to be working for me.

Astryl 11 years, 7 months ago

You're linking to the wrong libraries. You need the ones with an s at the end. So libsfml-graphics-s.a, libsfml-window-s.a, libsfml-system-s.a.

Astryl 11 years, 7 months ago

Could be the order of the referenced libraries.

Try using the right hand side of the linker options page instead, type these in:

-lsfml-graphic-s
-lsfml-window-s
-lsfml-system-s
-lsfml-main

Those are my settings.

EDIT: Never mind, didn't work. Getting a whole bunch of GCC spawned errors. What version of GCC are you using?

Astryl 11 years, 7 months ago

Oh, pardon. That's -lsfml-graphics-s. Missing s. But it still didn't work. I'll look into it in my spare time.

sirxemic 11 years, 7 months ago

If you link statically to SFML, you add -s to the lib filenames and you define SFML_STATIC

If you debug, you add -d.

e.g. linking statically in debug mode, the lib file libsfml-graphics.a becomes libsfml-graphics-s-d.a

I find it kind of silly that in an article on how to setup SFML, you forget these important things. Buuut I could be wrong of course, since I work with Visual Studio…

Astryl 11 years, 7 months ago

'twas mostly to help people migrating to the new libraries, not a full-blown tutorial for newcomers. Not really, anyway. Most people who should be using SFML can kinda figure out the suffix on the libraries.

sirxemic 11 years, 7 months ago

Quote:
Most people who should be using SFML can kinda figure out the suffix on the libraries.
Those people who are smart enough to figure that out themselves don't need your tutorial either. For example. this tutorial is worthless to Cyrus, it seems, since he forgot about the suffixes.

Whenever you write a tutorial, you should make some clear assumptions about the reader. What does he and what doesn't he know? How smart is the reader?

The official tutorial on the website addresses these issues, which makes me wonder - what made you write this tutorial?

Astryl 11 years, 7 months ago

Boredom.

svf 11 years, 7 months ago

Sfml 2 :)

Be prepared Laurent (the creator) is planning on changing more function names… ;-;

In later versions