Monday, November 17, 2014

How to setup SFML on Ubuntu 14.04 LTS - Update

Hi Folks,

it's been over six months since I wrote the article about compiling and installing SFML on Ubuntu 14.04. On 11.11 (no carnival joke ;-) the SFML Team announced that version 2.2 of the SFML library isn't far off and the team needs us developers to test if the new git commit builds and runs. 
Since I also re-installed my totally messed up development machine with a fresh Ubuntu 14.04, so it is perfect time to write an update for my old article while testing the new SFML build.
Since this is no official release from SFML, but just a git commit, I will incorporate git in the whole process, fetching the master branch from GitHub, compiling and installing it. Here we go...

Since I run this on a totally fresh Ubuntu installation, I start by creating some folders (to open a terminal hit ctrl+alt+t): 
~$ mkdir development
~$ cd development
~/development$ mkdir projects
~/development$ cd projects
~/development/projects$

I create the directory development in my home directory, and within that a directory for my projects. In the project-folder, I want to clone the SFML master branch from GitHub. In order to do this I need git, and because we need a compiler and cmake to actually build SFML, I install the following development tools:

sudo apt-get update
sudo apt-get install g++ cmake git

Now I clone the SFML repo:
~/development/projects$ git clone https://github.com/LaurentGomila/SFML.git

Now we could start to build SFML, but since this is a fresh installation we need all dependencies first. The official tutorial on compiling SFML lists the needed packages, and here are the actual package names for Ubuntu 14.04:

libx11-dev
freeglut3-dev
libjpeg-dev
libfreetype6-dev
libxrandr-dev
libglew-dev
libsndfile1-dev
libopenal-dev
libudev-dev

To install them all, run the following command: 
sudo apt-get install libx11-dev freeglut3-dev libjpeg-dev libfreetype6-dev libxrandr-dev libglew-dev libsndfile1-dev libopenal-dev libudev-dev

After this step I am able to configure and run the build with the following steps:

Switch to the SFML directory, in my case ~/development/projects/SFML/
and run the following commands:
cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=TRUE .
make
sudo make install

Note the dot at the end of the cmake-command, which tells cmake to use the actual directory as a working directory. There are only two relevant cmake switches, CMAKE_BUILD_TYPE (either Debug or Release) and BUILD_SHARED_LIBS (TRUE for dynamic linking, FALSE for static linking). In order to build all four configurations, you have to run the above three commands four times while alternating the two switches.

In order to link the SFML libraries in your projects, add them to the linker options in your project, e.g. in Code::Blocks:



After that you are finally able to develop, build and run SFML apps on Ubuntu 14.04 with the latest master build of SFML from GitHub.





No comments:

Post a Comment