A simple SFML 3 demonstration project configured for static linking on Windows using CMake.
This project demonstrates:
- Static linking of SFML 3 libraries on Windows
- CMake configuration for static builds
- Basic SFML 3 graphics and input handling
- Automated build script (Bootstrap.bat)
The demo application displays:
- A cyan circle that can be moved with keyboard controls
- A magenta rectangle that rotates continuously
- Smooth delta-time based movement
| Key | Action |
|---|---|
| W / ↑ | Move circle up |
| S / ↓ | Move circle down |
| A / ← | Move circle left |
| D / → | Move circle right |
| ESC | Close application |
Before building, ensure you have:
- Windows 10/11 (64-bit)
- Visual Studio 2026 with C++ Desktop Development workload
- CMake 3.22+ (Download)
- Git (Download)
sfml-demo/
├── Bootstrap.bat # Automated build script
├── CMakeLists.txt # CMake configuration
├── README.md # This file
└── main.cpp # Application source code
Simply run the Bootstrap script:
Bootstrap.batThis script will:
- Clone SFML 3.0.0 from GitHub (if not already present)
- Build SFML as static libraries (Debug & Release)
- Build the demo application with static linking
If you prefer to build manually:
cd C:\Repositories
git clone --branch 3.0.2 https://github.com/SFML/SFML
cd SFML
mkdir build && cd build
cmake .. -G "Visual Studio 18 2026" ^
-DCMAKE_INSTALL_PREFIX=..\install ^
-DBUILD_SHARED_LIBS=OFF ^
-DSFML_USE_STATIC_STD_LIBS=ON
cmake --build . --config Release --target install
cmake --build . --config Debug --target installcd path\to\sfml-demo
mkdir build && cd build
cmake .. -G "Visual Studio 18 2026" ^
-DSFML_STATIC_LIBRARIES=TRUE ^
-DSFML_ROOT="C:\Repositories\SFML\install"
cmake --build . --config Release| Option | Default | Description |
|---|---|---|
SFML_ROOT |
C:/Repositories/SFML/install |
Path to SFML installation |
SFML_STATIC_LIBRARIES |
TRUE |
Enable static linking |
CMAKE_CXX_STANDARD |
20 |
C++ standard version |
Edit the top of Bootstrap.bat to customize:
set BUILD_PARALLEL=12 # Parallel build jobs
set CMAKE_GENERATOR="Visual Studio 18 2026" # CMake generator
set CPP_STANDARD=20 # C++ standard
set REPOSITORIES_ROOT=C:\Repositories # Where to clone SFML
set SFML_VERSION=3.0.2 # SFML version to useThis project uses fully static linking:
- SFML Libraries: Built with
BUILD_SHARED_LIBS=OFF - MSVC Runtime: Uses
/MT(Release) and/MTd(Debug) - Result: Single standalone executable with no DLL dependencies
After building SFML, you'll find these libraries in C:\Repositories\SFML\install\lib\:
| Library | Release | Debug |
|---|---|---|
| System | sfml-system-s.lib |
sfml-system-s-d.lib |
| Window | sfml-window-s.lib |
sfml-window-s-d.lib |
| Graphics | sfml-graphics-s.lib |
sfml-graphics-s-d.lib |
| Audio | sfml-audio-s.lib |
sfml-audio-s-d.lib |
| Network | sfml-network-s.lib |
sfml-network-s-d.lib |
Ensure SFML is installed correctly:
dir C:\Repositories\SFML\install\lib\cmake\SFMLIf the directory is empty, rebuild SFML with the --target install option.
Common causes:
- Mixed static/dynamic linking: Ensure all libraries use the same runtime (
/MTor/MD) - Missing Windows libraries: The CMakeLists.txt includes
opengl32,winmm,gdi32
If Git clone fails:
- Check your internet connection
- Try cloning manually:
git clone https://github.com/SFML/SFML C:\Repositories\SFML cd C:\Repositories\SFML git checkout 3.0.2
This project uses SFML 3 which has API differences from SFML 2:
// SFML 3 VideoMode uses initializer list
sf::VideoMode({800, 600}) // SFML 3
sf::VideoMode(800, 600) // SFML 2
// SFML 3 event handling uses std::optional
while (const auto event = window.pollEvent())
{
if (event->is<sf::Event::Closed>())
window.close();
}
// SFML 3 angles use sf::degrees/sf::radians
shape.rotate(sf::degrees(45.0f));This demo project is released under the MIT License. See LICENSE for details.
SFML is licensed under the zlib/png license. See SFML License.