How to Set Up SFML in a Project on Visual Studio

Setting up SFML in Visual Studio 2017 or 2019 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. Highlight what you expect to...

Method 1 of 7:

Configuring and Downloading  

  1. Picture 1 of How to Set Up SFML in a Project on Visual Studio
    Highlight what you expect to do. For example see picture above.
  2. Select the version:  Visual Studio Community 2017 or 2019.
    1. Check the "Desktop development with C++" workload box.
  3. Create the "GL" folder. In directory (disk) C:, right click > select New > Folder > type GL < hit Enter.
  4. Download the latest stable version of SFML. Right click on following address and select Open Link in New Window https://www.sfml-dev.org/download/sfml/2.5.1/. Click the first "Download", the one next to "Visual C++ 15 (2017) - 32-bit".
    1. In downloading window, click the folder SFML-2.5.1 (or the latest) > right click > Copy.
    2. Navigate to C: > GL. In GL folder right click > select Paste.
    3. After copying and pasting have finished click on name SFML-2.5.1 and rename to sfml.
Method 2 of 7:

Creating an Empty Project

  1.   Create an empty project.
    1. With Visual Studio 2017
      1. In V.S. main menu, click File. Then go to New > Project…
      2. In the left part of the new project window, click Visual C++ if it is not clicked.
      3. In the center of the screen click Empty Project.
      4. Below that, find the Name text box, type Project-0.
      5. Next to Location text box, click Browse... and navigate to C: > GL.
      6. Click Select a folder. The Location in New Project window is C:GL.
      7. Make sure the Create directory for solution box is not checked.
      8. Click OK.
    2. With Visual Studio 2019
      1. If it's not opened. Open it > Click Create a new project > Empty Project > Next.
      2. In "Project name" text field type: Project-0. Next to "Location" text field click ....
      3. Navigate to C: > GL > click Select folder. Now "Location" is C:GL.
      4. Check "Place solution and project in the same directory" > click Create.
      5. Wait till Visual Studio 2019 instance appears.
      6. If it's opened. Click File > New > Project… > Empty Project > Next. The rest as above.
  2. Add a source file to Project. In Visual Studio > Solution Explorer > right click Source Files > Add > New Item... > C++ file (.cpp). Name it Main.cpp. Location should be C:GLProject-0. > click Add.
    1. The source file Main.cpp is now in Visual Studio's main area, and is blank. It's okay.
Method 3 of 7:

Setting Up SFML in the Project

  1. Open the Project-0 Property Pages window. In Solution Explorer right click the project's name (Project-0) > click Properties. Leave default settings: Configuration: Active(Debug), and Platform: Active(Win32).
  2. Configure the Additional Include Directories. In Project-0 Property Pages window double click C/C++ > click General > Additional Include Directories > the down arrow at the end of the field > click first icon  > ....
    1. Navigate C: > GL > sfml > include > Select a Folder. In the Additional Include Directories window, the path should be C:GLsfmlinclude. Click OK.
  3. Configure the Linker "Additional Library Directories". In the "Project-0 Property Pages" window, double click Linker > click General > Additional Libraries Directories > down arrow at the end of the field > Edit... >  first icon > ....
    1.  Navigate to C: > GL > sfml > lib > Select a Folder.
    2. In Additional Libraries Directories window, the path should be C:GLsfmllib. Click OK.
  4. Configure the linker "Additional Dependencies". In the "Linker" drop down menu, click Input > Additional Dependencies > down arrow at the end of the field > click .
    1. Copy the following .lib file names and paste in "Additional Dependencies" window's most top text box:
      1. opengl32.lib; 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
    2. In "Additional Dependencies" window click OK.
  5. Configure linker SubSystem. In Linker dropdown menu click System > SubSystem > down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE) > click Apply and OK.
  6. Copy .dll files from SFML and paste into the Project-Folder. Navigate to C: > GL > sfml > bin .
    1. 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.
    2. Navigate to C: > GL >Project-0. Inside, right click and select Paste. Now every .dll file is in project-folder.
  7. Test your project. Right click on following address and select Open Link in New Window https://www.sfml-dev.org/tutorials/2.5/start-vc.php scroll down the page and copy the code.
    1. Go to V.S. and paste in Main.cpp code area. Hit Ctrl + F5. Two windows should appear: a black (the console) and a small one with green circle inside. Good job.
  8. Correct any errors. In "Error List" if you see error about
    1. file with extension .h go to part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
    2. file with extension .lib go to part (Method) 3, step 2, "Configure the linker "Additional Library Directories"", and follow instructions. Also to step 3, "Configure the linker "Additional Library Directories"".
    3. "entry point must be defined" go to step 4, "Configure linker SubSystem" and follow instructions.
    4. file .dll go to step 5 and follow instructions.
    5. For other errors, if you cannot correct them, close Visual Studio > delete project folder Projetc-0 which lives in C:GL > open Visual Studio > repeat set up from part Method 2. Good job.
Method 4 of 7:

 Create a project with the Template

  1. Create Template. 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  > click Finish. The template is created.
  2. Create Project.
    1. With V.S. 2017. Click File > New > Project....
      1. On the New Project window, click template: SFML.
      2. In Name text field, type: Project-1. Be sure Create directory for solution is unchecked. Click  OK.
    2. With V.S. 2019. Click File > New > Project....
      1. In Create a new project wizard scroll down the list of templates and select SFML > click  Next.
      2. In Configure your new project wizard, in Project name text field type Project-1.
      3. Location should be C:GL. If it's not, click ... at the end of the field. Navigate C: > GL. Folder's name should be SFML. Click Select a folder.
      4. Be sure Place solution and project in the same directory is checked. Click Create.
  3. Copy the .dll files from bin folder as above, and paste them in the project folder Project-1.
  4. 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::Green to Color::Blue. 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.
Method 5 of 7:

Creating Project to target x64 Platform

  1. Create folder GL as above.
  2. Download the latest stable version of SFML 64 bit. Right click on following address and select Open Link in New Window https://www.sfml-dev.org/download/sfml/2.5.1/. Click the "Download", next to "Visual C++ 15 (2017) - 64-bit", the first in right column.
    1. In downloading window, click the folder SFML-2.5.1 (or the latest) > right click > Copy.
    2. Navigate to C: > GL. In GL folder right click > select Paste.
    3. After copying and pasting have finished click on name SFML-2.5.1 and rename to sfml.
  3. Create project with name Project-2, and add Main.cpp file as above.
  4. Project's Property settings. Go to "Solution Explorer" > right click on the name of your project > select "Properties". In Platform: entry, choose x64 > Click Configuration manager...
    1. In Active solution platform: select x64
    2. In Platform entry select x64
    3. Click Close
  5. The rest as above.
    1. Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
  6. Create template. As above.
    1. TIP: In every project you create with it, select x64 (next to Debug) in Visual Studio's GUI.
Method 6 of 7:

Compiling Source Code with CMake and Visual Studio

  1. Compiling a library from the source code benefits twofold. Guarantees that the resulting library is perfectly tailored for your CPU/OS, a luxury pre-compiled binaries don't always provide, and that binaries you get target x64 platform.
  2. Picture 2 of How to Set Up SFML in a Project on Visual Studio
    Highlight what you expect to do. For example see picture above.
  3. Create folder GL. In Windows File Explorer, in directory C:, right click on empty area > select New > Folder > type: GL > hit Enter.
  4. Picture 3 of How to Set Up SFML in a Project on Visual Studio
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/. Scroll down the page (see image above). Under "Latest Release (today is 3.16.2)" on the second "Platform" list, find "Windows win64-x64.ZIP" and click the beside entry (today is cmake-3.16.2-win64-x64.zip > in opening wizard select Save file.
  5. Copy and unzip the zip folder.
    1. In downloading window, click folder > right click > in drop-down menu select Copy.
    2. Navigate to directory C: > GL > right click > select Paste.
    3. When copying and unzipping (extracting files) is finished, double click unzip folder cmake-3.16.2-win64-x64 (or latest version) > bin > inside you should see CMake's logo next to file name cmake-gui > double click this file. If wizard "Windows protect your PC" appears, click More information > Run anyway. Now on your screen you have CMake GUI.
    4. Each time you need CMake, navigate to C: > GL > cmake-3.16.2-win64-x64 (or latest version) > bin > double click file cmake-gui (the one with CMake's logo).
  6. Download source code. Right-click on following address and select Open Link in New Window https://www.sfml-dev.org/download/sfml/2.5.1/. Scroll down to the bottom, in All select Source code and click Download 22.2 MB.
  7. Copy and unzip folder.
    1. In downloading window click zip folder SFML-2.5.1-sources.zip (or latest version) > right click > select Copy.
    2. Navigate to C: > GL > right click > select Paste.
    3. Now in directory C:GL, you have unzip folder SFML-2.5.1. Click twice on its name > delete name > type SFML > hit Enter.
  8. Where is the source code. Copy C:/GL/SFML and paste in CMake GUI first text field.
  9. Where to build the binaries. Copy C:/GL/SFML/build and paste in second text field.
  10. Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > click Finish.
    1. When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
  11. Build your solution.
    1. Navigate to C: > GL > SFML > build. Double click "SFML.sln", or "SFML", or "ALL_BUILD.vcxproj". An instance of Visual Studio appears. In the main menu, click "Build" > "Build Solution".
    2. Wait till you read the last line in "Output" window: ========== Build: 8 succeeded, 0 failed, 0 up-to-date, 1 skipped ==========
      1. TIP: Number of "succeeded" changes in SFML versions. Today (28-1-2020) is 8.
  12. Create an empty project. Click 'File > New > Project… > Create a new project > Empty project > Next.
    1. In Project name text box type: pb-0.
    2. Next to Location text box, click ....
    3. Navigate to C: > GL > Click Select a folder. The Location is C:GL.
    4. Check box Place solution and project in the same directory.
    5. Click Create.
  13. Add your source file to the Project. In Solution Explorer wizard, right click the Source Files folder (the last one) > click Add > New Item…
    1. In the Add New Item - pb-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box, type Main.cpp.
    2. The Location is C:GLpb-0.
    3. Click the Add button. The file will open in the main text editor but leave it blank for now.
  14. Configure project's Properties. In Solution Explorer wizard, right click Project's name that is pb-0 > select Properties.
    1. (1) pb-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
      1. In Active solution platform: select x64.
      2. In Platform entry, x64 is automatically selected.
      3. Click Close.
    2. (2) Additional Include Directories. Click C/C++ > General > In beside menu select the first one, Additional Include Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ...
      1. Navigate to C: > GL > SFML > include > click include > click Select a folder > click OK.
    3. (3) Additional Library Directories. Double click Linker > click General > Additional Library Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ....
      1. Navigate to C: > GL > SFML > build > lib > Debug. Click Select a folder > click OK. In Additional Library Directories wizard path should be C:GLSFMLbuildlibDebug.
    4. (4) Additional Dependencies. In Linker drop-down menu select Input > in beside menu select the first one, Additional Dependencies > click the down arrow at the end of the field > Edit... > copy opengl32.lib; sfml-audio-d.lib; sfml-graphics-d.lib; sfml-main-d.lib; sfml-network-d.lib; sfml-system-d.lib; sfml-window-d.lib and paste in Additional Dependencies wizard's upper-most text box > click OK.
    5. (5) Set System to SubSystem CONSOLE. In Linker drop-down menu select System > in beside menu select the first one, SubSystem > click the down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE). Click Apply and OK.
  15. Copy dll files and paste in pb-0 project. In File Explorer click File > Open new Window. In new (second) window navigate to C: > GL > SFML > build > lib > Debug, and copy (by right click > Copy), one by one, all 5 (five) dll files, and paste in first window C: > GL > pb-0. Now in project folder pb-0 you have the 5 DLL files among Source.cpp and other 4 files created by Visual Studio.
  16. Test your project and correct errors if any. As above, see Method 3 Setting Up SFML in the Project.
  17. Create Template with pb-0 project. As above, Method 4 Create a project with the Template. Remember in every project you create with this template
    1. select x64 in Visual Studio's GUI.
    2. copy DLL files from previous project and paste in new.
Method 7 of 7:

Choosing Set Up

  1. In this tutorial you learn 3 was to set up SFML in Project with Visual Studio.
    1. Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
    2. Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
    3. Compile SFML source, and set up in project. Targets x64 too.The most difficult. The best though.
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile