Pages

Tuesday, May 7, 2013

Great Success! Get SFML to work with Code::Blocks IDE

Hello!
I said I'd report back, and that's what I'm doing. I know I'm a couple of days late, but, better late than never right?

On to the good news. I finally managed to get SFML to work. How? Well, the boys over at SFML-dev have updated their website, source code and tutorial quite recently. With this brand spanking new update, alot of things have been fixed. That means it's much easier to set up and use. I shall guide you through the process now (which is the main reason why you're here, right?).

Note that this tutorial is intended for Code::Blocks IDE on Windows. If you're using another one, try their official documentation first.

  1. Go the the Code::Blocks download page and grab yourself a binary release WITH the MingW compiler. If you're into building from source, they have those as well.
  2. Install or unpack it.
  3. Write yourself a small C++ program in Code::Blocks to make sure that it's set up properly. If it compiles and runs fine, then you've got the easy bit done.
  4. Now scoot on over to the SFML download page and grab the GCC 4.7 TDM (SJLJ) version (either 32 or 64 bit depending on you're system). In my experience the DW2 version gave me errors. If the SJLJ version gives you errors, try DW2. 
  5. Unpack the contents of the zip on your hard drive (somewhere safe, with read and write privileges). Open up the directory and locate the include and lib folders. Remember them.
  6. Go to Code::Blocks, click on the settings menu bar, and go to compiler. In older versions of Code::Blocks, it's called compiler and debugger.
  7. Under Global Compiler Settings, search for the Search Directories tab and click on it. Now, in this tab, you have more subtabs, two of which are called compiler and linker.
  8. Under the compiler tab, add the directory to SFML's include folder from step 5. So if you unpacked the zip to the root of your C: drive, an example of the directory would be C:\SFML-2.0\include.
  9. Under the linker tab, add the directory to SFML's lib folder from step 5. If unpacked to the same place, an example would be C:\SFML-2.0\lib. Click OK to apply your settings
  10. Phew. Okay, now we need to add SFML's libraries to the linker. Next to the Search Directories tab is a Linker settings tab. Click it.
  11. Under Link Libraries, add the following libraries IN THIS ORDER. i.e click on add, navigate to the lib folder in SFML, and add libsfml-graphics.a, libsfml-audio.a, libsfml-window.a and then libsfml-system.a (libsfml-graphics.a must be at the top, libsfml-system.a must be at the bottom). If you're project is using some networking libraries as well, don't forget libsfml-network.a as well.
  12. Click OK and apply all settings. Now, navigate to the bin folder in your SFML directory and copy all the .dll files into the folder your project's executable is found, which should be the bin folder of your project.
  13. Time to test out your code. Create a main.cpp and enter this code:
Now compile, and run. Voila!

Okay, if this doesn't work for you, let me know.

No comments:

Post a Comment