Getting and Using SFML
What do I need to use SFML 3?
SFML 3 requires a compiler with C++17 support. The minimum versions are:
| Compiler | Version |
|---|---|
| MSVC | 16 (VS 2019) |
| GCC | 9 |
| Clang | 9 |
| AppleClang | 12 |
If you build SFML from source, you also need CMake 3.28 or newer, see SFML requires a newer CMake version than my OS provides! if your system doesn't provide it.
If you use the prebuilt packages from the download page, your compiler has to match the one they were built with, see The prebuilt libraries don't work with my compiler.
What's the easiest way to start a new SFML project?
Use the CMake project template. It downloads and builds SFML as part of your project, so you don't have to download, build or install SFML yourself, and it works the same with every compiler and IDE that supports CMake.
See the CMake template tutorial for the details.
Can I install SFML with a package manager?
Yes, SFML is available from several package managers, for example:
- vcpkg on Windows, Linux and macOS
- Homebrew on macOS (
brew install sfml) - MSYS2 on Windows for MinGW
- The package repositories of most Linux distributions
These packages aren't maintained by the SFML Team and may lag behind the latest SFML release, especially on Linux distributions with long release cycles. Check which version you get before following a tutorial, as SFML 2 and SFML 3 aren't API compatible.
How do I build SFML?
Tutorials for each version of SFML can be found here. The first part of these tutorials is aimed at getting started, which includes building SFML with CMake and your build tool of choice, as well as setting up your IDE (if you use one) for use with SFML.
Are there any "nightly builds"?
Our CI (continuous integration) system is building every commit on the master branch and saving the built binaries as artifacts, ready to be downloaded. You can find them either by commit hash or branch name.
How do I setup my development environment to work with SFML?
This is covered quite thoroughly in the tutorials section for some of the most popular IDEs.
Check out the Getting Started sections of the tutorials.
What dependencies does SFML have?
SFML depends on a few other libraries, such as FreeType and HarfBuzz for text, FLAC and Vorbis for audio, and MbedTLS and libssh2 for the network module.
When building SFML with CMake, these dependencies are downloaded and built as part of SFML, unless the SFML_USE_SYSTEM_DEPS option is enabled.
On Windows, macOS, Android and iOS, the option is disabled by default, so compilation works out of the box.
On Linux, the option is enabled by default and SFML uses the libraries installed on your system instead.
Additionally, the windowing and system libraries (X11, Xrandr, Xcursor, Xi, udev, OpenGL) always have to be installed on Linux.
See the build from source tutorial for the full list, and don't forget to install the development version of these packages.
SFML also has internal dependencies: Audio, Network and Window depend on System, while Graphics depends on Window and System. See What and how do I link to use SFML? for what this means for your project.
What and how do I link to use SFML?
When you want to use SFML, you need to link to the library files that provide the functionality you make use of in your application.
If you use CMake, which is the recommended way, link the SFML targets of the modules you use and CMake takes care of the rest, including the dependencies and their order:
find_package(SFML 3 REQUIRED COMPONENTS Graphics Audio)
target_link_libraries(my-app PRIVATE SFML::Graphics SFML::Audio)
If you set up your build manually, keep reading.
SFML is divided into 5 modules:
- System provided by sfml-system
- Window provided by sfml-window
- Graphics provided by sfml-graphics
- Audio provided by sfml-audio
- Network provided by sfml-network
Be aware that the modules have interdependencies on each other. For instance, if you plan on using the Graphics module, you will also have to link against the Window and System modules as well.
Dependencies:
- System does not depend on anything and can be used by itself.
- Window depends on System.
- Graphics depends on Window and System.
- Audio depends on System.
- Network depends on System.
As you can see you will always have to link against sfml-system, no matter what you do.
Be aware that some linkers are sensitive to the order in which you specify libraries to link against.
GCC (which implies MinGW as well) requires that the dependees (libraries that others depend on) are specified after the dependers (libraries that depend on others).
An example of a GCC command line linking all modules would be as follows:
This is explained as well in this forum post.
In Code::Blocks for example you would have to make sure the dependees come after the dependers in the list of libraries to link against.
How do I link SFML statically?
If you use CMake, set SFML_STATIC_LIBRARIES to ON before calling find_package(SFML ...), and CMake takes care of the defines and the dependencies.
Otherwise, you'll need to setup your build environment to link against the static libraries of SFML.
Static libraries are the ones with a -s suffix, for example sfml-graphics-s.
Next, you'll need to add SFML_STATIC to the preprocessor option and, as always, you'll need to make sure to link the debug libraries (-s-d suffix) in debug mode and the release libraries (no -d suffix) in release mode.
In the past, SFML included on Windows all its dependencies into the SFML libraries. However, this was changed to eliminate multiple issues and get a commonly expected behavior (full discussion). Now, SFML behaves the same on Linux as well as on Windows, which however means, that you need to link SFML's dependencies on your own when linking statically. Since the dependencies aren't obvious to everyone, here's a listing for SFML 3.1:
Windows
- sfml-graphics
- sfml-window
- sfml-system
- opengl32
- harfbuzz
- freetype
- sfml-window
- sfml-system
- opengl32
- winmm
- gdi32
- sfml-audio
- sfml-system
- flac
- vorbisenc
- vorbisfile
- vorbis
- ogg
- sfml-network
- sfml-system
- libssh2
- mbedtls
- mbedx509
- mbedcrypto
- ws2_32
- crypt32
- dnsapi
- bcrypt
- sfml-system
- winmm
Example
Here's a diagram showing how the static linking should look like.
sfml-window-s sfml-system-s opengl32 winmm gdi32
| | | | |
| +-------+ | | |
| | +------------------+ | |
| | | +--------------------------+ |
| | | | +-------------------------------+
| | | | |
v v v v v
example.exe
Is there a complete list with all the changes from SFML 2.x to SFML 3.0?
See the official migration guide to get your code base updated to SFML 3.