Copy-pasted from here.
Anybody who has been spying on me thanks to Twitter, Facebook or whatever other
communistsocial
ist 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-pastaNote 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-rcUnzip it somewhere sensible. I use
C:\Dev\SFML-2.0-rcNow 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 libraryThe 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 <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <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-pastaOne + 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.
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.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.
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.
Could be the order of the referenced libraries.
Try using the right hand side of the linker options page instead, type these in:Oh, pardon. That's -lsfml-graphics-s. Missing s. But it still didn't work. I'll look into it in my spare time.
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.aI 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…'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.
Boredom.
Sfml 2 :)
Be prepared Laurent (the creator) is planning on changing more function names… ;-;In later versions