3.3 KiB
Setting up SDL on Windows
Note: this project no longer uses SDL, but I wanted to keep the documentation around on how to set up and configure SDL on Windows because it was particularly weird.
As a side note, there is a cool tool called Scoop
that you could use to install a lot of these tools. However, I ran into an issue using the Scoop versions of SDL2 because the directory names were different from what the header files were expecting. Below I just installed everything manually instead.
Install SDL2
Download the "devel mingw" versions of the following SDL2 releases (again, ideally the latest versions, just providing links for examples).
- SDL2 https://github.com/libsdl-org/SDL/releases/download/release-2.24.0/SDL2-devel-2.24.0-mingw.zip
- SDL2_Image https://github.com/libsdl-org/SDL_image/releases/download/release-2.6.2/SDL2_image-devel-2.6.2-mingw.zip
- SDL2_TTF https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.20.1/SDL2_ttf-devel-2.20.1-mingw.zip
- SDL2_Mixer https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.6.2/SDL2_mixer-devel-2.6.2-mingw.zip
Extract the zip files (you can use 7zip or the built-in Windows zip tool) to get a directory for each. They should look something like SDL2_ttf-2.20.1
.
Then put these all in some folder you will remember, something like C:\Users\Username\SDL2
.
You should end up with 4 folders inside the SDL2
folder you created, one for each of the things we downloaded.
Set environment variables
Now that we've downloaded SDL, we need to set some environment variables so that everything will know where we installed it.
We need to set our "include" path. This is all of the directories that contain C header files to be included in our code. We need this to include the default GCC include directory as well as each of the SDL2 library include directories that we downloaded. This might be easier to copy-paste yourself if the versions are different. Also, change the Username
to match your actual username (use search-replace to make this easier).
C_INCLUDE_PATH = C:\Users\Username\GCC\x86_64-12.1.0-release-win32-seh-rt_v10-rev3\mingw64\include;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\include\SDL2;
Then we need to set our "library" path. This is all of the directories that contain compiled library files (on Windows these are *.dll
files) that can be imported into our code. This only needs to add all of the SDL2 directories.
LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\lib;
Copy the SDL2 libraries into your code directory
Your code may compile successfully, but it might not run because of the missing SDL2 libraries. Copy each of the *.dll
library files into your code directory so that your resulting binary can load them correctly.
The DLL files should be in each of the bin
directories of the SDL2 libraries that you downloaded.