Translator: This article is the fourth in the translation cycle of the official SFML library guide. Past article can be found here. This series of articles aims to provide people who do not know the original language 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 start.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 explain how to install SFML, set up an interactive development environment and compile a program using 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 more detailed acquaintance 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 a fourth or later version, which is available on the App Store ) and clang.
With the latest versions of Xcode, you must also install the Command Line Tools from Xcode> Preferences> Downloads> Components.
Binary files: dylib (dynamic libraries) or frameworks
SFML for Mac OS X is available in two versions. On the one hand there are dynamic libraries, on the other side of the framework packages. Both variants are presented in the form of
universal binaries , so they can be used on Intel 32-bit or 64-bit systems without adapting to a specific platform.
Dylib is represented by dynamic libraries (this is something like files with the .so extension on Linux). You can find out more in
this dynamic library documentation . Frameworks are somewhat similar to dynamic libraries, except that they can encapsulate external resources. More detailed framework documentation is available
here .
There is only one difference between these two types of libraries that you should consider when developing your applications: if you compiled 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. It is for this reason that only binary files for release configuration are available on
the download page for OS X.
Xcode Templates
SFML comes with two templates for Xcode 4 and later, which allow you to create new projects very quickly and easily. 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 that contains all the application resources (the installation process for your application is very 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. A guide to how to do this is beyond the scope of this article. Please refer to the Apple Xcode 3 documentation.
C ++ 11, libc ++ and libstdc ++
Xcode comes with a version of clang and libc ++, which partially supports C ++ 11 (that is, some new features have not yet been implemented). If you plan to use the new features of C ++ 11, you must configure the project to use clang and libc ++.
However, if your project depends on libstdc ++ in (directly or indirectly), you need to build SFML yourself and customize the project accordingly.
SFML installation
First you need to 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 the lib into / usr / local / lib and copy the contents of the include into / usr / local / include.
- Frameworks
Copy the contents of Frameworks to / Library / Frameworks.
- SFML dependencies
SFML on Mac OS X is dependent on some libraries. Copy the contents of extlibs into / Library / Frameworks.
- Xcode Templates
This feature is optional, but we strongly 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 SFML App creates a project for an application package. Here we will use the latter, but both options work the same way.
First select File> New Project ..., then select SFML in the left column and double click on SFML App.

You can now fill in the required fields, as shown in the following screen shot. When you are done click the Next button.

Your project is now configured 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 choose C ++ 11 with Clang and libc ++.
- If you compiled SFML yourself, you should be able to figure out which option to use. ;-)
Now your project is ready, let's see what we got:

As you can see, there are already several files in the project. There are three important file types:
- Header and source code files: the project comes with a basic example in the main.cpp file and an auxiliary function
std::string resourcePath(void);
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 package.
. 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 base examples are located in this directory and are automatically copied into your application package when you compile it.
To add new resources to your project, simply drag and drop them into this folder and make sure they become members of the target application.
- Products: your applications. Just click the Run button to check 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 done so that your application can run on another Mac without installing SFML or its dependencies.
Next article:
Compiling SFML with CMake