# SFML 2 Linux Development How to install and get SFML development working on Linux. This version uses an Ubuntu Linux operating system and the SFML 2.1 installation guide: "SFML ## Set Up ### 1. Create a project directory to contain your SFML files as well as your C++ application files. ### 2. Download the SFML packages located here ("Download SFML") to your project directory. ### 3. This should contain a bz2 package. Unpack it using: ``` bash tar -xvf sfml-package.bz2 ``` ### 4. This should unpack into a directory such as SFML-2.1 ### 5. Create a main.cpp file in your project base folder which should now look like * project/main.cpp * project/SFML-2.1/ ### 6. Edit your main.cpp file and add SFML test code: ``` cpp #include int main() { sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Green); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); window.draw(shape); window.display(); } return 0; } ``` ## Compiling ### 1. If not installed, install g++ on your Linux operating system. Using Ubuntu: ``` bash sudo apt-get install g++ ``` ### 2. Since we are using the manually downloaded SFML files, we will need to compile with an include to the SFML headers ``` bash g++ -c main.cpp -ISFML-2.1/include ``` ### 3. This will create the output file main.o. Your directory will now look like: * main.cpp * main.o * SFML-2.1/ ### 4. Since we are using manually downloaded SFML files, we will need to link the libraries directly ``` bash g++ main.o -o sfml-app -LSFML-2.1/lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network ``` ### 5. If the following errors appear: /usr/bin/ld: warning: libGLEW.so.1.5, needed by lib/libsfml-graphics.so... /usr/bin/ld: warning: libjpeg.so.62, needed by lib/libsfml-graphics.so... You need to install libglew1.5 and libjpeg62 ``` bash sudo apt-get install libglew1.5 libjpeg62 ``` ### 6. The executable binary will be output as sfml-app It is important to note that Linux applications do not statically link libraries. This basically enforces dynamically linked libraries for anyone using the application. Some approaches to more or less package the game could be: * List the dependencies required on the installation page, e.g. SFML 2.1 * Include the .so library files in the download and run a shell script to set up the path * Determine another packaging solution (perhaps handled by Steam installers etc.) ## Running ### 1. Since we are using manually downloaded SFML files, we will need to export the library files to the OS path: ``` bash export LD_LIBRARY_PATH=/home/path/to/SFML-2.1/lib ``` ### 2. Run the application ``` bash ./sfml-app ``` ![](/images/SFMLLinuxResult.png)