Logo Glusoft
Glusoft
Become a Patron! Buy me a coffee!

Static build with Visual Studio

Why do we want to link SDL2 statically ?

Let's count the number of dll :

For SDL2:

SDL2.dll

For SDL2_image:
SDL2_image.dll
libjpeg-9.dll
libpng16-16.dll
libtiff-5.dll
libwebp-4.dll
zlib1.dll

For SDL2_ttf:
SDL2_ttf.dll
libfreetype-6.dll
zlib1.dll

For SDL2_mixer:
SDL2_mixer.dll
libFLAC-8.dll
libmodplug-1.dll
libogg-0.dll
libvorbis-0.dll
libvorbisfile-3.dll
smpeg2.dll

For SDL2_gfx:
SDL2_gfx.dll

So if you use everything there are 17 dll files to include (one zlib1.dll is enough).

But wait there is more:
With visual studio your program is probably compiled with \MD which means the run-time library is a dll. So the user will need to have the package Visual C++ Redistributable for Visual Studio installed to run the app.

The first thing to do is to link the static version of the run-time library with your app, for that change \MD to \MT (for Release) in the Project Properties -> C/C++ -> Code Generation -> Runtime Library

All the SDL libraries are compiled with the flag \MD so we will recompile every library and change \MD to \MT.

SDL2 static


Compile SDL2

You should obtain: SDL2.lib and SDL2main.lib (SDL2-VS2015.zip).

SDL2 dependencies

Here is the list of dependencies to add in the Linker -> Input of the project you want to compile:

winmm.lib
imm32.lib
version.lib

These libraries are already included in visual studio so it should not be necessary to include them with other lib files.

SDL2_image static

Compile SD2_image

You should obtain: SDL2_image.lib (SDL2_image.lib for VS2015)

SDL2_image dependencies

You will have to compile the libraries in the folder SDL2_image-2.0.1/external/, don't forget to pick the static version or add \MT if you have a visual studio project.
You can find other resources on how to compile these libraries.
You should obtain: libpng16.lib, libwebp.lib, libjpeg.lib and zlib.lib (SDL2_image_dep-VS2015.zip).

You need to include these in the linker, if you use tiff image you also need to add libtiff-5.dll (SDL2_image-2.0.1/VisualC/external/lib)

SDL2_ttf static

Compile SD2_ttf

You should obtain: SDL2_tff.lib (SDL2_ttf.lib for VS2015)

SDL2_ttf dependencies

There is only the library freetype to compile statically linked: SDL2_ttf-2.0.14/external/freetype-2.4.12.
You should obtain: libfreetype-6.lib (libfreetype-6.lib for VS2015)

SDL2_mixer static

Compile SD2_mixer

SDL2_mixer dependencies

SDL2_gfx static

Compile SD2_gfx

You should obtain: SDL2_gfx.lib (SDL2_gfx.lib for VS2015)

SDL2_gfx dependencies

There is no dependencies!

Project Test


When you create a project with all the libraries you should include for the linker:
winmm.lib
imm32.lib
version.lib
SDL2main.lib
freetype2412.lib
SDL2_ttf.lib
zlib.lib
libpng16.lib
libwebp.lib
libjpeg.lib
SDL2_image.lib
timidity.lib
libFLAC_static.lib
smpeg.lib
libmodplug.lib
libogg_static.lib
libvorbis_static.lib
win_utf8_io_static.lib
SDL2.lib
libvorbisfile_static.lib
SDL2_gfx.lib
SDL2_mixer.lib
and have two dll:
smpeg.dll
SDL.dll

You can download the test project (with all includes an libs) for VS2015: TestSDL.zip

Post Comments
Dark theme