Skip to content

RichardDally/SFMLStatic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SFML 3 Static Demo

A simple SFML 3 demonstration project configured for static linking on Windows using CMake.

Overview

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)

Features

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

Controls

Key Action
W / ↑ Move circle up
S / ↓ Move circle down
A / ← Move circle left
D / → Move circle right
ESC Close application

Prerequisites

Before building, ensure you have:

  1. Windows 10/11 (64-bit)
  2. Visual Studio 2026 with C++ Desktop Development workload
  3. CMake 3.22+ (Download)
  4. Git (Download)

Project Structure

sfml-demo/
├── Bootstrap.bat       # Automated build script
├── CMakeLists.txt      # CMake configuration
├── README.md           # This file
└── main.cpp            # Application source code

Build Instructions

Quick Build (Recommended)

Simply run the Bootstrap script:

Bootstrap.bat

This script will:

  1. Clone SFML 3.0.0 from GitHub (if not already present)
  2. Build SFML as static libraries (Debug & Release)
  3. Build the demo application with static linking

Manual Build

If you prefer to build manually:

1. Build SFML (Static)

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 install

2. Build the Demo

cd 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

Configuration

CMake Options

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

Bootstrap.bat Settings

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 use

Static Linking Details

This 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

Resulting Static Libraries

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

Troubleshooting

"SFML not found" Error

Ensure SFML is installed correctly:

dir C:\Repositories\SFML\install\lib\cmake\SFML

If the directory is empty, rebuild SFML with the --target install option.

Linker Errors (Unresolved Symbols)

Common causes:

  1. Mixed static/dynamic linking: Ensure all libraries use the same runtime (/MT or /MD)
  2. Missing Windows libraries: The CMakeLists.txt includes opengl32, winmm, gdi32

Build Fails on Clone

If Git clone fails:

  1. Check your internet connection
  2. Try cloning manually:
    git clone https://github.com/SFML/SFML C:\Repositories\SFML
    cd C:\Repositories\SFML
    git checkout 3.0.2

SFML 3 API Changes

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));

License

This demo project is released under the MIT License. See LICENSE for details.

SFML is licensed under the zlib/png license. See SFML License.

Resources

About

GNU/Linux SFML Static compilation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors