# Setting up SFML on Windows, OS X and Linux

Tags: Programming

This is a small guide I wrote for Warwick Game Design to get people started with C++ game development with SFML on whatever platform they prefer. Provided that platform is Windows, OS X or Linux. Hopefully it won’t take too much time to get through – if you have any trouble, feel free to email me. If you find any problems or confusing sections please let me know – I wrote it in one sitting, so there are bound to be mistakes.

To start, we’ll install a development environment of your choice – you may have one set up already. We’ll then install the Simple and Fast Media Layer (SFML) library, which is the only external library you’ll need to get started writing some simple games.

I assume that you have some familiarity with the idea of a terminal/command line/console. Wherever I say to enter a command, I mean for you to use a command line. Where I list commands like

$ls ~/somedir$ g++ ~/somedir/somefile.cpp

$brew install make ### Installing SFML Using libraries in unix-like systems is usually as simple as installing them through your distro’s package manager: • Ubuntu, Debian and Linux Mint: $ sudo apt-get install libsfml-dev
• Arch Linux:

$sudo pacman -S sfml • MSYS2: $ sudo pacman -S mingw-w64-sfml-git
• OS X:

$brew install sfml Otherwise, you should follow the SFML install guide. ### Writing a “Hello World” program Once you’re happy with your development environment, the next thing you should do is write a simple C++ program to make sure everything is set up properly.The typical first program in any language is one which outputs “Hello World!” to the screen and then exits. Let’s try that. #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; } Write this out and save it to hello_world.cpp. There’s a surprising amount going on here. First we include “iostream” from the C++ standard library, which provides input and output in the form of streams. We define a function main with type int (integer number). main is always the function where our program starts, and it must always return an int (in this case 0); however, in C++ we can leave out return 0 for main as this is the default (NB: no other function allows this!). We output the string “Hello world!” as a stream, using the << “output stream” operator, which sends the string to cout (standard output) and ends it with endl (end line). cout and endl are defined in the standard library, and live in the std namespace, which prevents collisions between different libraries. This means we need to prepend them with std:: to ensure we get the cout we expected. Now we want to compile our code, $ g++ -o my_program hello_world.cpp

and then run it:

\$ ./my_program

This should print “Hello World!” in the terminal (or debug output in VS).

#### Hello Rectangle

Ok, great. We can write text to a terminal. Next, we want to display something graphical. I ran out of time writing this here, but you can continue on your own with the SFML tutorials.