<< Back

How to Install SFML in XCode

On This Page

  1. Introduction
  2. Installing XCode
  3. Installing SFML
  4. Creating an SFML Project

A. Introduction

This document describes how to install SFML on XCode 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 Linux computers, see How to Install Code::Blocks and SFML for Linux.

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 XCode

SFML does not require the latest version of XCode. Any version starting with Lion (10.7) or later is acceptable and there is no need to update to the latest version of XCode.

Installing XCode

If you do not have XCode or want to update, use the following instructions:

  1. Register as an Apple developer at https://developer.apple.com/programs/register/.

    Registering as an Apple developer is free for individuals. The Apple website may imply that you must pay, but the link should take you directly to the free signup page.

  2. Go to Apple Developer and login.

    After login, you can download the latest version of XCode in the Mac App Store as well as older versions.

  3. Once downloaded, install XCode from the disc image (dmg) file. Drag and drop the file into your computer's Application folder.
  4. After installing XCode, download and install the command-line tools as well.

    Command-line tools can be downloaded from the Apple Developer. Some versions of XCode allow you to install the command-line tools from: XCode > Preferences > Downloads > Command Line Tools.

To learn how to use XCode, look up tutorials on the Apple Developer site or with a search engine.

More Information

C. Installing SFML

  1. Go to the SFML download page and follow the link to the latest stable version.
  2. Download the SFML libraries for your version of XCode and place them in a suitable location.

    Use Clang for OS X 10.7 (Lion 2012) or later. Earlier versions of OS X do not have pre-built downloads.

  3. Open the Terminal application.

    The Terminal application is located in the Utilities subfolder of the Applications folder.

  4. In the Terminal window, cd to the download location.

    For example: cd Downloads

  5. Run the install script by typing: ./install.sh followed by the Enter key.

    The script will prompt you for your password and install the components correctly.

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.

  1. Start XCode and select File > New Project... then choose SFML in the left column and double-click on SFML App.

    Starting a n SFML project.

  2. In the next window, fill in the required fields and then press the Next button.

    Example project test-sfml

  3. In the main.cpp file, copy and paste the following program code.
    #include <SFML/Graphics.hpp>
    int main()
        sf::RenderWindow win(sf::VideoMode(200, 200), "SFML Test");
        sf::CircleShape shape(100.f);
        while (win.isOpen())
            sf::Event event;
            while (win.pollEvent(event))
                if (event.type == sf::Event::Closed)
        return 0;
  4. Run the project and verify you see the following graphics window.

    Verify test graphics

More Information

<< Back