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 Visual Studio
Introduction
This tutorial is the first one you should read if you're using SFML with the Visual C++ compiler. It will explain how to
install SFML, setup your IDE, and compile a SFML program.
Compiling SFML libraries is also explained, for more advanced users (although it's quite simple).
SFML is maintained using VC++ 2005 Professional, but the following explanations are valid for other versions such as VC++ 2005 Express, VC++ 9, VC++ 7 or even VC++ 6.
Installing SFML
First, you must download the SFML development files. You can download the minimal package (libraries + headers), but
it is recommended that you download the full SDK, which contains samples and documentation as well.
If you want to use the Graphics or Audio packages, you also need to download the external libraries used by SFML.
This package contains the DLLs of these libraries, which will be needed to run any SFML program. If you only want to
use the System, Window or Network packages, you don't need any external library.
All the mentioned packages can be found on the
download page.
Once you have downloaded and extracted the files to your hard drive, you must make the SFML headers and library files available for Visual C++. There are two ways of doing it :
- Copy the SFML development files to your Visual Studio installation directory
- Copy SFML-x.y\include\SFML to the VC\include directory of your Visual Studio installation (so that you obtain VC\include\SFML)
- Copy the *.lib files in SFML-x.y\lib\vc2005 to the VC\lib directory of your Visual Studio installation (or SFML-x.y\lib\vc2008, if you're using Visual C++ 2008)
- Leave the SFML files where you want, and setup Visual Studio so that it can find them
- Go to the Tools / Options menu, then to Projects and Solutions / VC++ Directories
- In Include files, add SFML-x.y\include
- In Library files, add SFML-x.y\lib\vc2005 (or SFML-x.y\lib\vc2008 if you're using Visual C++ 2008)
Compiling your first SFML program
Create a new "Win32 console application" project, and write a SFML program. For example, you can try the
sf::Clock class of the System package :
#include <SFML/System.hpp> #include <iostream> int main() { sf::Clock Clock; while (Clock.GetElapsedTime() < 5.f) { std::cout << Clock.GetElapsedTime() << std::endl; sf::Sleep(0.5f); } return 0; }
Don't forget that all SFML classes and functions are in the sf namespace.
Open your project's options, then go to the Linker / Input item. In the Additional dependencies row,
add the SFML libraries you are using. Here we only use sfml-system.lib. For the Debug configuration, you can
link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case).
This is for the dynamic version of the libraries, the one using the DLLs. If you want to link with the static
version of the libraries, add the "-s" suffix : sfml-system-s.lib, or sfml-system-s-d.lib for the debug version.
Your program should now compile, link and run fine. If you linked against the dynamic versions of the SFML libraries, donc forget to copy the corresponding DLLs (sfml-system.dll in this case) to your executable's directory, or to a directory contained in the PATH environment variable. If you link against dynamic libraries, you also need to define the SFML_DYNAMIC macro for your project.
If you are using the Audio package, you must also copy the DLLs of the external libraries needed by it, which
are libsndfile-1.dll, and OpenAL32.dll.
These files can be found in the extlibs\bin directory that you downloaded with the SDK.
Compiling SFML (for advanced users)
If the precompiled SFML libraries don't exist for your system, you can compile them quite easily. In such case, no test have been made so you are encouraged to report any failure or success encountered during your compile process. If you succeed compiling SFML for a new platform, please contact the development team so that we can share the files with the community.
To compile SFML libraries and samples, you must first download and install the full SDK.
Go to SFML-x.y\build\vc2005, and open the file SFML.sln. Choose the configuration you want to build (Debug or Release, Static or DLL), and clic "build". This should create the corresponding SFML library files in lib\vc2005, as well as the sample executables. If Qt and wxWidgets are not installed on your system, you may get compile errors with the corresponding samples ; just ignore them.
