This is a complete set of instructions to install and configure your environment to use SDL2, SDL2_image, and SDL2_ttf on Windows 11, primarily using the command line (winget and pacman).
The core of the setup is using MSYS2 as it provides the easiest command-line installation and linking for MinGW-w64 and the SDL extension libraries.
Open a standard Command Prompt (CMD) or PowerShell for these steps.
We use MSYS2 to get the MinGW-w64 toolchain, which includes the g++ compiler, and to manage the SDL libraries.
-
Install MSYS2:
winget install MSYS2.MSYS2
-
Launch MSYS2 and Update:
-
Open the Windows Start Menu and launch MSYS2 MinGW 64-bit. This opens a special terminal.
-
Run the following commands to update and ensure the system is current:
pacman -Syu # If prompted, close the terminal, re-open MSYS2 MinGW 64-bit, and run: pacman -Su
-
-
Install MinGW-w64 Toolchain and SDL Libraries:
-
Still in the MSYS2 MinGW 64-bit terminal, install the C/C++ toolchain (
g++) and the SDL2, SDL2_image, and SDL2_ttf development packages for 64-bit Windows (x86_64):pacman -S --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-SDL2_ttf
-
Press Enter to select all members of the
toolchaingroup, and then type 'y' to proceed with the installation.
-
winget Git.GitYou need to add the MinGW bin directory to your system's PATH so the g++ command works from any terminal, including the standard Windows Command Prompt.
-
Open a new standard Command Prompt (not the MSYS2 terminal).
-
Add the compiler directory to the system PATH. The default location is:
C:\msys64\mingw64\bin.setx PATH "%PATH%;C:\msys64\mingw64\bin" -
Crucial: You must close and re-open your Command Prompt or PowerShell for the new PATH to take effect.
-
Open a new standard Command Prompt and create your project folder:
mkdir C:\inro-to-programming cd C:\inro-to-programming
-
Download the course repository and copy the sampe files from lectures:
git clone https://github.com/stranxter/lecture-notes robocopy '.\lecture-notes\samples\01_programming 101\2025-26-kn\drawing' . /E
For your executable to run, it needs the dynamic-link libraries (.dll files) in the same directory. Copy them from the MSYS2 installation path:
In your Command Prompt in the C:\intro-to-programming directory:
copy C:\msys64\mingw64\bin\SDL2.dll C:\intro-to-programming
copy C:\msys64\mingw64\bin\SDL2_image.dll C:\intro-to-programming
copy C:\msys64\mingw64\bin\SDL2_ttf.dll C:\intro-to-programmingUse g++ to compile and link your program. You must include the new linker flags for SDL2_image and SDL2_ttf.
In your Command Prompt in the C:\intro-to-programming directory:
g++ main.cpp draw/sdlwrapper.cpp -o my_sdl_program.exe -std=c++17 -Wall -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttfImportant Linker Order: The libraries are listed in order of dependency. The primary SDL libraries must come after SDL2main.
Execute your program from the Command Prompt:
.\my_sdl_program.exe