SFML is a great alternative for developing 2D games, in addition to other multimedia resources.
On Windows it is very easy to use it with Visual Studio, however, there are those who prefer to use SFML in their Code Editor/IDE and also use another compiler instead of MSVC.
In this article we will see how to compile your projects in SFML with GCC with MinGW on Windows.
First of all, you must have GCC/G++ with MinGW properly installed on your system, and to do so, if you don’t have it installed yet, just follow the steps in this tutorial:
After properly installing and running GCC/G++ with MinGW, the next step is to download a different SFML package (different from the Visual Studio version).
And for that, access the downloads page of the SFML website at the link: https://www.sfml-dev.org/download/sfml/2.5.1/ and download the version: GCC 7.3.0 MinGW (SEH) - 64-bit
as shown below:
If you want to download it right here, just click the button below:
Download GCC 7.3.0 MinGW (SEH) - 64-bit
The downloaded file will have the name and extension: SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
, extract this file by right-clicking it and choosing Extract here
.
After extracted there will be a folder named: SFML-2.5.1
, I renamed it to just SFML
.
It will be easier to use when compiling.
Now enter this folder (SFML
) and copy all the files that are inside the subfolder: bin
to the “root” of your project and then copy the entire SFML
folder also to the “root” of your project, the files are:
After listing the files with the
ls
command of PowerShell inside my project folder:MyProjectSFML
.
In addition to the SFML
folder and the files copied from the SFML\bin
subfolder, there is also the main.cpp
file that contains the code that we are going to compile, if you want to use it as a test, use the code below:
Now let’s compile!
To compile, just enter your project through PowerShell or CMD
and run the command:
Note the use of the parameters: -I
(include) and -L
(lib) with the respective directories to the SFML
folder that is inside our project. And also the flags:
If you are creating code with Audio and/or Network add the flags:
-lsfml-audio -lsfml-network
.
Now just run the binary and run to the hug:
If you want to use Makefile or a script in Lua to facilitate the compilation command, stay tuned willing! We show you how to do this in the article about Images with SDL2.