<< Back

How to Install Code::Blocks and SFML for Linux

By Ethan Berman with some additions by Ed Parrish

On This Page

  1. Introduction
  2. Installing Code::Blocks
  3. Installing SFML Using CMake
  4. Creating an SFML Project

A. Introduction

This document describes how to install Code::Blocks and SFML on Linux for the course CS-11: Introduction to Programming Concepts and Methodology, C++. For Windows computers, see How to Install SFML in Code::Blocks for Windows. For Macintosh computers, see How to Install SFML in OS-X.

Code::Blocks is an Integrated Development Environment (IDE) used by many C++ software engineers and developers. An IDE is like a text editor with added features. It runs on the major platforms including Linux, OS-X and Windows. Code::Blocks is free, open source and configurable for use with different compilers including GCC/G++.

SFML is a free and open source library that provides a simple object-oriented interface to graphics, sound and other parts of a personal computer. It has five main modules: system, window, graphics, audio and network.

B. Installing Code::Blocks

Code::Blocks can usually be installed in your distributions's app repositories. Use the following steps to install Code::Blocks.

  1. Open a Terminal window and type the following at the command line:
    sudo apt-get update
    sudo apt-get install codeblocks
  2. Answer "y" when prompted.

More Information

C. Installing SFML Using CMake

The latest version of SFML is not typically stored as a binary in app repositories and thus often needs to be downloaded and compiled from source.

  1. Open a Terminal window and type the following at the command line:
    sudo apt-get install cmake
  2. Next install the SFML dependencies by entering the following commands in the Terminal window:
    sudo apt-get install libpthread-stubs0-dev
    sudo apt-get install libgl1-mesa-dev
    sudo apt-get install libx11-dev
    sudo apt-get install libxrandr-dev
    sudo apt-get install libfreetype6-dev
    sudo apt-get install libglew1.5-dev
    sudo apt-get install libjpeg8-dev
    sudo apt-get install libsndfile1-dev
    sudo apt-get install libopenal-dev

    If you have problems with dependencies, see Installing dependencies.

  3. Make a dedicated directory for SFML, to keep things organized, like:
    mkdir /home/<your user name>/development/sfml/
  4. In the Terminal window, change to the dedicated directory like:
    cd ~/development/sfml
  5. Download the source into the directory. For example:
    wget https://github.com/SFML/SFML/tarball/master
    tar zxf master
    rm master

    Another download option is from the SFML Download page.

  6. Rename the directory that appears in your SFML directory to "sfmlbuild" (without the quotes).
    mv oldname sfmlbuild
  7. Change to the dedicated directory like:
    cd sfmlbuild
  8. Run the following CMake command:
    cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=TRUE

    Read through the notifications that appear and verify that CMake did not fail. If CMake did fail, recheck your steps.

  9. Prepare the source and install by typing:
    sudo make install

    If the make commands fail, it is usually caused dependencies. See see Installing dependencies.

  10. Repeat the CMake process as follows:
    cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=TRUE .
    sudo make install
    cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=FALSE .
    sudo make install
    cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=FALSE .
    sudo make install

    Make sure that after every CMake command you also enter the make and make install commands or else SFML will not actually install.

  11. At this point we can run Code::Blocks and access the SFML libraries.

    Either click a shortcut to launch Code::Blocks or type the following in the Terminal window:


More Information

D. Creating an SFML Project

In this section we create a test project to verify the SFML installation. We can use these instructions as a starting point for other new projects as well.

The Code::Blocks procedure for using SFML is similar between Windows and Linux. Follow the Creating an SFML Project instructions in the document How to Install SFML in Code::Blocks for Windows.

<< Back