This is a minimal example on how to use SDL2.
Recommanded setup on Windows if you don't have Visual Studio (e.g. you only have Visual Studio Code)
- Use the following instructions. It boils down to:
- Installing MSYS2
- Installing the MinGW-w64 toolchain using
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
- Adding the path to gcc.exe to the system PATH variable. Likely you'd want to modify it from Environment variables editor in Windows Settings, so that it points to
C:\msys64\ucrt64\bin
- Download the libSDL2 development package for MinGW from here.
- E.g., use SDL2-devel-2.30.1-mingw.zip
- Install CMake — any version later than 3.7 is OK.
- Make a "SDK" directory, either in a "develop" subfolder in your user directory (e.g.
C:\Users\«USERNAME»\develop\SDK
) or in C:\ - Unarchive the SDL2-devel there, e.g. so that CMake can see
C:\Users\«USERNAME»\develop\SDK\SDL2-2.30.1\cmake
To compile sdl-minimal
manually:
- Create a "build" directory:
mkdir build
- Change into it:
cd build
- Run CMake, targeting MinGW:
cmake -G "MinGW Makefiles" ..
- Run
make
to build your code
To run it:
- Copy SDL2.dll from SDL2\x86_64-w64-mingw32\bin\ to your "build" directory
- You're all set - run
sdl-minimal.exe