<< 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. If you do not have Xcode or want to update, use the following instructions:

  1. Register as an Apple developer at https://appleid.apple.com/account.

    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 the Mac Dev Center and login.

    After login, you can download the latest version of XCode 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 Mac Dev Center. 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.8 or later and GCC for older versions of Xcode.

  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);
        shape.setFillColor(sf::Color::Green);
    
        while (win.isOpen())
        {
            sf::Event event;
            while (win.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                {
                    win.close();
                }
            }
    
            win.clear();
            win.draw(shape);
            win.display();
        }
    
        return 0;
    }
    
  4. Run the project and verify you see the following graphics window.

    Verify test graphics

More Information

<< Back