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
- Highlight what you expect to do. For example see picture above.
- Select the version: Visual Studio Community 2017 or 2019.
- Check the "Desktop development with C++" workload box.
- Create the "GL" folder. In directory (disk) C:, right click > select New > Folder > type GL < hit ↵ Enter.
- 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".
- In downloading window, click the folder SFML-2.5.1 (or the latest) > right click > Copy.
- Navigate to C: > GL. In GL folder right click > select Paste.
- 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
- Create an empty project.
- With Visual Studio 2017
- In V.S. main menu, click File. Then go to New > Project…
- In the left part of the new project window, click Visual C++ if it is not clicked.
- In the center of the screen click Empty Project.
- Below that, find the Name text box, type Project-0.
- Next to Location text box, click Browse... and navigate to C: > GL.
- Click Select a folder. The Location in New Project window is C:GL.
- Make sure the Create directory for solution box is not checked.
- Click OK.
- With Visual Studio 2019
- If it's not opened. Open it > Click Create a new project > Empty Project > Next.
- In "Project name" text field type: Project-0. Next to "Location" text field click ....
- Navigate to C: > GL > click Select folder. Now "Location" is C:GL.
- Check "Place solution and project in the same directory" > click Create.
- Wait till Visual Studio 2019 instance appears.
- If it's opened. Click File > New > Project… > Empty Project > Next. The rest as above.
- With Visual Studio 2017
- 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.
- 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
- 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).
- 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 > ....
- Navigate C: > GL > sfml > include > Select a Folder. In the Additional Include Directories window, the path should be C:GLsfmlinclude. Click OK.
- 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 > ....
- Navigate to C: > GL > sfml > lib > Select a Folder.
- In Additional Libraries Directories window, the path should be C:GLsfmllib. Click OK.
- Configure the linker "Additional Dependencies". In the "Linker" drop down menu, click Input > Additional Dependencies > down arrow at the end of the field > click .
- Copy the following .lib file names and paste in "Additional Dependencies" window's most top text box:
- 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
- In "Additional Dependencies" window click OK.
- Copy the following .lib file names and paste in "Additional Dependencies" window's most top text box:
- 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.
- Copy .dll files from SFML and paste into the Project-Folder. Navigate to C: > GL > sfml > 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: > GL >Project-0. Inside, right click and select Paste. Now every .dll file is in project-folder.
- 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.
- 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.
- Correct any errors. In "Error List" if you see error about
- file with extension .h go to part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
- 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"".
- "entry point must be defined" go to step 4, "Configure linker SubSystem" and follow instructions.
- file .dll go to step 5 and follow instructions.
- 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
- 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.
- Create Project.
- With V.S. 2017. Click File > New > Project....
- On the New Project window, click template: SFML.
- In Name text field, type: Project-1. Be sure Create directory for solution is unchecked. Click OK.
- With V.S. 2019. Click File > New > Project....
- In Create a new project wizard scroll down the list of templates and select SFML > click Next.
- In Configure your new project wizard, in Project name text field type Project-1.
- 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.
- Be sure Place solution and project in the same directory is checked. Click Create.
- With V.S. 2017. Click File > New > Project....
- 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::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
- Create folder GL as above.
- 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.
- In downloading window, click the folder SFML-2.5.1 (or the latest) > right click > Copy.
- Navigate to C: > GL. In GL folder right click > select Paste.
- After copying and pasting have finished click on name SFML-2.5.1 and rename to sfml.
- Create project with name Project-2, and add Main.cpp file as above.
- 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...
- In Active solution platform: select x64
- In Platform entry select x64
- Click Close
- The rest as above.
- Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
- Create template. As above.
- 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
- 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.
- Highlight what you expect to do. For example see picture above.
- Create folder GL. In Windows File Explorer, in directory C:, right click on empty area > select New > Folder > type: GL > hit ↵ Enter.
- 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.
- Copy and unzip the zip folder.
- In downloading window, click folder > right click > in drop-down menu select Copy.
- Navigate to directory C: > GL > right click > select Paste.
- 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.
- 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).
- 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.
- Copy and unzip folder.
- In downloading window click zip folder SFML-2.5.1-sources.zip (or latest version) > right click > select Copy.
- Navigate to C: > GL > right click > select Paste.
- Now in directory C:GL, you have unzip folder SFML-2.5.1. Click twice on its name > delete name > type SFML > hit ↵ Enter.
- Where is the source code. Copy C:/GL/SFML and paste in CMake GUI first text field.
- Where to build the binaries. Copy C:/GL/SFML/build and paste in second text field.
- Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > click Finish.
- When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
- Build your solution.
- 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".
- Wait till you read the last line in "Output" window: ========== Build: 8 succeeded, 0 failed, 0 up-to-date, 1 skipped ==========
- TIP: Number of "succeeded" changes in SFML versions. Today (28-1-2020) is 8.
- Create an empty project. Click 'File > New > Project… > Create a new project > Empty project > Next.
- In Project name text box type: pb-0.
- Next to Location text box, click ....
- Navigate to C: > GL > Click Select a folder. The Location is C:GL.
- Check box Place solution and project in the same directory.
- Click Create.
- Add your source file to the Project. In Solution Explorer wizard, right click the Source Files folder (the last one) > click Add > New Item…
- 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.
- The Location is C:GLpb-0.
- Click the Add button. The file will open in the main text editor but leave it blank for now.
- Configure project's Properties. In Solution Explorer wizard, right click Project's name that is pb-0 > select Properties.
- (1) pb-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- In Active solution platform: select x64.
- In Platform entry, x64 is automatically selected.
- Click Close.
- (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 ...
- Navigate to C: > GL > SFML > include > click include > click Select a folder > click OK.
- (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 ....
- 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) 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) 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.
- (1) pb-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- 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.
- Test your project and correct errors if any. As above, see Method 3 Setting Up SFML in the Project.
- 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
- select x64 in Visual Studio's GUI.
- copy DLL files from previous project and paste in new.
Method 7 of 7:
Choosing Set Up
- In this tutorial you learn 3 was to set up SFML in Project with Visual Studio.
- Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
- Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
- Compile SFML source, and set up in project. Targets x64 too.The most difficult. The best though.
3.6 ★ | 11 Vote
You should read it
- How to Create an Executable File from Eclipse
- How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio
- How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio
- How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio
- How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio
- How to Open an MPP File on PC or Mac
- Toshiba will be the main supplier for Project Ara
- How to Set Up SDL with Visual Studio
- How to Add JARs to Project Build Paths in Eclipse (Java)
- Latest Project XL code and how to enter Project XL code
- How to Play Sounds for Calendar Notifications on a Mac
- How to Make a Bug in GIMP
Maybe you are interested
How to use Auto Clicker Assist to automatically click the mouse
Instructions to fix double click error on computer mouse - Click once becomes twice
PowerToys will soon support creating app spaces and launching with just one click
Turn Windows 11 interface into Windows 10 with just one click
Fix right-click issue on Windows 10
Do not click on strange links or your phone will be hijacked