WARNING : this is the documentation for an old version of SFML ; the documentation for the latest official release is available through the main menu
Tutorial - Getting started - SFML and Mac OSX (Xcode)
Introduction
This tutorial is the first one you should read if you'ure using SFML with Xcode IDE and gcc (the default compiler).
It will show you how to install SFML, setup your IDE, and compile a simple SFML program.
It also explains how to compile SFML libraries, for advanced users.
Note that SFML is compatible with any Mac Intel or PPC using at least Mac OS X 10.4. It may also be compatible with Mac OS X 10.3.9, but it hasn't been tested on this OS.
Installing SFML
First, you have to download the SFML development files. You can get the minimal package (libraries + headers), but
it is advised to get the full SDK, which contains on top of that the samples and the documentation.
All these packages can be found on the
download page.
Once you've downloaded and installed the files on your hard drive, copy the contents of the SFML-x.y/lib/xcode directory to the /Library/Frameworks directory. The minimal installation is finished.
However, in order to make using SFML easier, we also provide project templates for Xcode. To use them, copy the "SFML Window-based Application" and "SFML Graphics-based Application" directories from SFML-x.y/build/xcode/templates to "/Developer/Library/Xcode/Project Templates/Application", as well as the "SFML Tool" directory to "/Developer/Library/Xcode/Project Templates/Command Line Utility".
Create your first SFML program
Start Xcode, and choose "File" > "New Project..." in the main menu.
Select the "Application" part on the left side. Here is what you should see:
Choose one of the SFML projects, and click on "Choose...". You'll be prompted to enter a name for your project, which will also be the name of your program.
To test the program, click on the "Build and Go" button of the toolbar in the project's window. Voilà, your application has been created!
Some explanations regarding the project:
- The "Sources" reference folder contains the source files of your program. You can add yours at this location.
- The "Frameworks" reference folder contains all the framewors used by your project. Here you can see that the sfml-system, sfml-window and sfml-graphics packages have been added. The "SFML.framework" package is there so that you can easily access the SFML header files. It's not used by the program, unlike the sfml-system, sfml-window and sfml-graphics frameworks. It's here that you'll add the frameworks of other SFML packages you'll need later. To do so, just drag and drop the package you need (sfml-xxx.framework) from the Finder to this reference folder.
If you want to create an executable rather than an application, the "SFML Tool" template is available in the "Command Line Utility" part of the new project dialog box. This template contains no code except the main function, and is linked to sfml-system.
Compiling SFML (for advanced users)
To compile the SFML frameworks and samples, you first have to download the full SDK (see the download page).
Go to the SFML-x.y/build/xcode directory and open the SFML.xcodeproj project (compatible with Xcode 2.4 and +). According to what you need, choose the target (Debug or Release), and launch the compile process. It can last a few minutes, depending on the power of your PC. You will then find the built frameworks in the SFML-x.y/lib/xcode directory.
Similarly, if you want to create the raw dynamic libraries, you can use the SFML-bare.xcodeproj project. The compile process produces dynamic libraries (files with the "dylib" extension) in the same SFML-x.y/lib/xcode folder.
Note: to provide a reditributable application or program, you must distribute the framework(s) or library(ies) with it, or install them in the system's default directories. The frameworks are meant to be copied in the applications' packets in <application>.app/Contents/Frameworks, or in the /Library/Frameworks directory. The raw dynamic libraries are meant to be copied directly with the executable, or in the /usr/local/lib directory. Raw libraries should be used instead of the frameworks if you plan to create an executable rather than an application.
To compile the samples, open the SFML-x.y/samples/build/xcode/samples.xcodeproj project and launch the comiple process. The built programs are located in the SFML-x.y/samples/bin directory. To launch these samples, the frameworks must have been installed in the system default directory.
