Install SFML 2.5.1 library for VisualStudio 2022 C++ Project

Download from Official Site

SFML Offcial Site

SFML Download Page

SFML Github Page

Creating and configuring a SFML project

You should create a main.cpp file and add it to the project, so that we have access to the C++ settings (otherwise Visual Studio doesn’t know which language you’re going to use for this project). We’ll explain what to put inside later.

In the project’s properties, add:

  • The path to the SFML headers (/include) to C/C++ » General » Additional Include
  • The path to the SFML libraries (/lib) to Linker » General » Additional Library Directories

Set SFML globally for project (“All configurations”)

Afet enter project, Project -> project Properties

Need to tell the compiler where to find the SFML headers (.hpp files), and the linker where to find the SFML libraries (.lib files).

  • headers C/C++ -> General -> Additional Include Directories

C:\usr\Library\SFML-2.5.1-windows-vc15-64-bit\include

  • libraries Linker -> General -> Additional Library Directories

C:\usr\Library\SFML-2.5.1-windows-vc15-64-bit\lib

link your application to the SFML libraries (.lib files) that your code will need. SFML is made of 5 modules (system, window, graphics, network and audio), and there’s one library for each of them.

Linker -> Input -> Additional Dependencies

sfml-system.lib
sfml-window.lib
sfml-graphics.lib
sfml-network.lib
sfml-audio.lib

Linking

dynamic

when compile the project, and if you linked to the dynamic version of SFML, don’t forget to copy the SFML DLLs (they are in <sfml-install-path/bin>) to the directory where your compiled executable is. Run it, and if everything should work.

static

Starting from SFML 2.2, when static linking, you will have to link all of SFML’s dependencies to your project as well. This means that if you are linking sfml-window-s.lib or sfml-window-s-d.lib for example, you will also have to link opengl32.lib, winmm.lib and gdi32.lib. Some of these dependency libraries might already be listed under “Inherited values”, but adding them again yourself shouldn’t cause any problems.

Here are the dependencies of each module, append the -d as described above if you want to link the SFML debug libraries:

  • sfml-graphics-s.lib
sfml-window-s.lib
sfml-system-s.lib
opengl32.lib
freetype.lib
  • sfml-window-s.lib
sfml-system-s.lib
opengl32.lib
winmm.lib
gdi32.lib
  • sfml-audio-s.lib
sfml-system-s.lib
openal32.lib
flac.lib
vorbisenc.lib
vorbisfile.lib
vorbis.lib
ogg.lib
  • sfml-network-s.lib
sfml-system-s.lib
ws2_32.lib
  • sfml-system-s.lib
winmm.lib

Example code for main.cpp

#include <SFML/Graphics.hpp>

int main()
{
	sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
	sf::CircleShape shape(100.f);
	shape.setFillColor(sf::Color::Green);

	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 0;
}

If you are using the sfml-audio module (regardless whether statically or dynamically), you must also copy the DLL of the external library needed by it, which is OpenAL32.dll. These files can be found in <sfml-install-path/bin> too.