How to Install SFML for Windows

How to Install SFML for Windows

In this article, we'll cover how to install the Simple and Fast Multimedia Library (SFML) for C++ projects for Windows. If you'd like to SFML for Mac, please see this article instead: How to Install SFML for Mac


Installing SFML

1. Navigate to the SFML website at https://www.sfml-dev.org/

2. Click the download link from the top menu, and then select the latest stable version download for SFML.



3. On the Download page, pick either the 32-bit version or 64-bit version. Then, download both the compiler and the matching GCC of SFML. Note you MUST install the correct version of MinGW as well (https://sourceforge.net/projects/mingw/files/latest/download)!



4. Once downloaded, unzip the file.
5. Rename the unzipped folder "SFML" and move it to the main C:\ drive folder.
6. Once that’s done, you’ve successfully installed SFML! You should be able to #include any SFML module in your projects now.

Compiling with SFML

When compiling C++ code using SFML, we need to tell the compiler where to find the SFML libraries as well as manually link the library of each module that we need. As we will ultimately need Graphics, Audio, Window, and System, we may as well link them all now by running the command:

  1. g++ -IC:\SFML\include -c main.cpp -o main.o

This links all of the include files and creates the main.o file. Before running the program, you're going to need to put the executable in a folder with the SFML dynamic libraries (DLLs). So, copy the bin folder from the SFML installation folder to your project folder, and move your executable to inside this bin folder.

Last, we want to link all of the library files and create the executable file. Do so with this command:
  1. g++ -LC:\SFML\lib -o main.exe main.o -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system