How to Set Up SFML in a Project on Visual Studio 2017


Setting up SFML in Visual Studio 2017 is similar to setting up SDL, GLFW, freeGLUT, and GLEW, with two peculiarities: there are 29 .lib files and 11 .dll files.

It is assumed your platform is Windows 7.

Part 1
Configuring and Downloading

Configuring and Downloading on How to Set Up SFML in a Project on Visual Studio 2017

1
Select "Visual studio 2017 Community". Check the "Desktop development with C++" workload box.

Configuring and Downloading on How to Set Up SFML in a Project on Visual Studio 2017

2
In directory C: create (by right click > New > Folder) a new folder called SFML.

Configuring and Downloading on How to Set Up SFML in a Project on Visual Studio 2017

3
Load up . Click the first "Download", the one next to "Visual C++ 15 (2017) - 32-bit". In the downloading window, click the folder and drag it (or, by right click, "Copy" and "Paste") into C: > SFML.

Part 2
Creating an Empty Project

Creating an Empty Project on How to Set Up SFML in a Project on Visual Studio 2017

1
Go to the Visual Studio main menu. Click File > New > Project... > Visual C++ > Empty Project > name it Project-0 > for Location, click Browse... Navigate C: > SFML > hit Select a Folder. The location should be: C:\SFML\. Uncheck "Create directory for solution" if it's checked > click OK.

Creating an Empty Project on How to Set Up SFML in a Project on Visual Studio 2017

2
In Visual Studio > Solution Explorer > right click "Source Files" > Add > New Item... > C++ file (.cpp). Name it "Main.cpp," and next to Location: click Browse.... Navigate to C: > SFML > Project-0 > hit Select a Folder. The location should be: C:\SFML\Project-0 > click Add. The source file Main.cpp is now in Visual Studio's main area, and is blank.

Part 3
Setting Up SFML in the Project

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

1
In "Solution Explorer" right click the project's name (Project-0). Click Properties > double click C/C++ > General > Additional Include Directories. Hit the down arrow at the end of the field > Edit... > first icon > .... Navigate C: > SFML > SFML-2.5.1 > include > Select a Folder. In the Additional Include Directories window, the path should be C:\SFML\SFML-2.5.1\include. Click OK.

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

2
In the "Project-0 Property Pages" window, double click Linker > click General > Additional Libraries Directories. Then hit the down arrow at the end of the field > Edit... > first icon > .... Navigate to C: > SFML > SFML-2.5.1 > lib > Select a Folder. In Additional Libraries Directories window, the path should be C:\SFML\SFML-2.5.1\lib. Click OK.

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

3
In the "Linker" drop down menu, click Input > Additional Dependencies. Hit the down arrow at the end of the field > Edit... . Copy the following .lib file names and paste in "Additional Dependencies" window's most top text box: flac.lib; freetype.lib; ogg.lib; openal32.lib; sfml-audio.lib; sfml-audio-d.lib; sfml-audio-s.lib; sfml-audio-s-d.lib; sfml-graphics.lib; sfml-graphics-d.lib; sfml-graphics-s.lib; sfml-graphics-s-d.lib; sfml-main.lib; sfml-main-d.lib; sfml-network.lib; sfml-network-d.lib; sfml-network-s.lib; sfml-network-s-d.lib; sfml-system.lib; sfml-system-d.lib; sfml-system-s.lib; sfml-system-s-d.lib; sfml-window.lib; sfml-window-d.lib; sfml-window-s.lib; sfml-window-s-d.lib; vorbis.lib; vorbisenc.lib; vorbisfile.lib Click OK in the "Additional Dependencies" window. Click Apply and OK in the "Project-0 Property Pages" window.

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

4
dll files from SFML and paste into the Project-Folder. Navigate to C: > SFML > SFML2.5.1 > bin . Inside the bin folder, click the empty area below the .dll files. Keeping the button pressed, move (hover) pointer over all files. Every file should have a light blue background color. Leave left button and with the pointer over background color, right click > select Copy. Navigate to C: > SFML >Project-0. Inside, right click and select Paste. Now every .dll file is in project-folder.

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

5
Copy the program below, paste it in "Main.cpp" code area, and click the green arrow in Visual Studio's main menu. Two windows should appear: a black one and a small one with name "SFML works!", and inside a blue cycle. If does not appear, try to correct any errors. If you fail, repeat the steps above. #include <SFML/Graphics.hpp> int main() { sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Blue); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); window.draw(shape); window.display(); } return ; }

Setting Up SFML in the Project on How to Set Up SFML in a Project on Visual Studio 2017

6
Go to the Visual Studio main menu. While Project-0 is open, click "Project" > Export Template... > Next.... In Select Template Options window in "Template name:" text field type SFML > hit Finish. The template is created. In Visual Studio main menu, click File > New > Project... > Visual C++ > template SFML. Name it "Project-1" and set the location to C:\SFML\. Leave "Create directory for solution" unchecked and hit OK. Copy the .dll files from bin folder as above, and paste them in the project folder Project-1. In Solution Explorer, double click Source Files > double click Main.cpp. (If the code does not appear, delete this file and create another with same name, copy above code and paste in code area). In the Main.cpp code, go to line 7 and rename Color::Blue to Color::Yellow. Click Ctrl+F5. Now the circle in small window should be yellow. Try to correct any errors if they occur. If you fail, repeat the steps above. When you create a project with a Template, you should copy .dll files.