1.4 SFML and Xcode (Mac OS X)
- Transfer
- Tutorial

From a translator: this article is the fourth in a series of translations of the official SFML library guide. A past article can be found here. This series of articles aims to provide people who do not know the original language with the opportunity to get acquainted with this library. SFML is a simple and cross-platform multimedia library. SFML provides a simple interface for developing games and other multimedia applications. The original article can be found here . Let's get started.
Table of contents:
0.1 Introduction
1. Getting Started
2. System module
3. Window module
4. Graphics module
5. Audio module
6. Network module
1. Getting Started
- SFML and Visual Studio
- SFML and Code :: Blocks (MinGW)
- SFML and Linux
- SFML and Xcode (Mac OS X)
- Compiling SFML with CMake
2. System module
3. Window module
- Opening and managing windows
- Event handling
- Work with keyboard, mouse and joysticks
- Using OpenGL
4. Graphics module
- 2D drawing objects
- Sprites and textures
- Text and Fonts
- Forms
- Designing your own objects with vertex arrays
- Position, rotation, scale: transforming objects
- Adding special effects with shaders
- 2D camera and view control
5. Audio module
- Playing sounds and music
- Audio recording
- Custom audio streams
- Spatialization: 3D sounds
6. Network module
- Socket Communication
- Use and expansion of packages
- Web Requests Using HTTP
- FTP File Transfer
Introduction
This is the first article you should read if you are using SFML with Xcode, and if you are developing applications for Mac OS X in general. It will tell you how to install SFML, set up an interactive development environment, and compile a program that uses SFML. More importantly, it will explain how to make your applications ready for use out of the box for end users.
This article has external links. They are intended for a more detailed familiarization with the topic.
System requirements
All you need to create an application using SFML is:
- Intel Mac with Max OS X Lion or later (10.7+)
- Xcode (preferably the fourth or later version available on the App Store ) and clang.
With the latest versions of Xcode, you must also install Command Line Tools from Xcode> Preferences> Downloads> Components.
Binary files: dylib (dynamic libraries) or frameworks
SFML for Mac OS X is available in two flavors. There are dynamic libraries on the one hand, and framework packages on the other. Both options are presented in the form of universal binary files , therefore they can be used on 32-bit or 64-bit Intel systems without adaptation to a specific platform.
Dylib is represented by dynamic libraries (this is something like files with the .so extension on Linux). You can learn more in this dynamic library documentation . The frameworks are somewhat similar to dynamic libraries, except that they can encapsulate external resources. More detailed documentation on frameworks is available here .
There is only one difference between these two types of libraries that you should consider when developing your applications: if you built SFML yourself, you can use dynamic libraries in debug and release configurations. However, frameworks are only available in the release configuration. In any case, this is not a problem if you want to use the release version of SFML when releasing your application. For this reason , only binaries for the release configuration are available on the download page for OS X.
Xcode Templates
SFML comes with two templates for Xcode 4 and later that make creating new projects very quick and easy. These templates will help you customize your project: you can choose the modules that your application requires, whether you want to use SFML using dynamic libraries or using frameworks and whether you need to create an installation package containing all the application resources (it’s very easy to complete the installation process of your application simply). See below for more details.
Keep in mind that these templates are not compatible with Xcode 3. If you are still using this version of the IDE and you do not want to update it, you can still create SFML applications. Guidance on how to do this is beyond the scope of this article. Please refer to the Apple documentation for Xcode 3.
C ++ 11, libc ++ and libstdc ++
Xcode comes with a version of clang and libc ++ that partially supports C ++ 11 (that is, some new features are not yet implemented). If you plan to use the new C ++ 11 features, you need to configure your project to use clang and libc ++.
However, if your project depends on libstdc ++ in (directly or indirectly), you must build SFML yourself and configure the project accordingly.
Install SFML
First you must download the SFML SDK from the download page . Then, in order to start developing SFML applications, you must install the following elements:
- Header files and libraries
SFML is available either as dynamic libraries or as frameworks. Only one type is required although both can be installed simultaneously on the same computer. We recommend using frameworks.- Dynamic Libraries
Copy the contents of lib to / usr / local / lib and copy the contents of include to / usr / local / include. - Frameworks
Copy the contents of Frameworks to / Library / Frameworks.
- Dynamic Libraries
- SFML dependencies SFML
on Mac OS X depends on some libraries. Copy the contents of extlibs to / Library / Frameworks. - Xcode Templates
This feature is optional, but we highly recommend installing it. Copy the SFML directory from templates to / Library / Developer / Xcode / Templates (if one or more directories are missing, create it (them)).
Creating Your First SFML Program
We provide two templates for Xcode. SFML CLT generates a project for a classic terminal program, while the SFML App creates a project for an application package. Here we will use the latter, but both options work the same.
First select File> New Project ..., then select SFML in the left column and double-click on the SFML App.

Now you can fill in the required fields, as shown in the following screenshot. When you are finished click Next.

Your project is now set up to create an application package (file with the extension ".app").
A few words about presets. If you choose an incompatible option for the C ++ compiler and the standard library, you will end up with a linker error. Make sure you follow this recommendation:
- If you downloaded the Clang version from the download page, you should select C ++ 11 with Clang and libc ++.
- If you compiled SFML yourself, you should be able to figure out which option should be used. ;-)
Now your project is ready, let's see what happened:

As you can see, there are already several files in the project. There are three important types of files:
- Header files and source files: the project comes with a basic example in the main.cpp file and a helper function
in ResourcePath.hpp and ResourcePath.mm. The purpose of this function, as shown in the examples, is to provide a convenient way to access the Resources directory of your packagestd::string resourcePath(void);
. Please note that this function only works on Mac OS X. If you want your application to work on other operating systems, you must implement your own version of this function. - Resource files: the resources of the basic examples are in this directory and are automatically copied to your application package when you compile it.
To add new resources to your project, just drag them to this folder and make sure that they become members of the target application. - Products: your applications. Just click the Run button to test your application.
Other files in the project are not very important for us. Remember that SFML and its dependencies are added to your application package. This is to ensure that your application can be run on another Mac without installing SFML or its dependencies.
Next article: Compiling SFML with CMake