Static-linking of SDL2 libraries

It’s not necessary to recompile the library,
SDL2 is given with static-link library named “libSDL2.a”
on the folder “SDL2-2.0.0\i686-w64-mingw32\lib\”.

Just be sure to add these options to the linker :

“-lmingw32 -lSDL2main -lSDL2 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc”

on Code:Blocks at “Project / Build Options… / Linket settings / Other linker options”

These options allow you to link with what SDL2.dll was using.

You can retreive them on the file “SDL2-2.0.0\i686-w64-mingw32\bin\sdl2-config”

The magical trick is to delete or rename the file “libSDL2.dll.a”
on the folder “SDL2-2.0.0\i686-w64-mingw32\lib\”.
I added a “-” before to keep it in case I need it.

I don’t know why this librairy overcomes the other and a clue would be appreciated.

I tried with Code::Blocks 12.11 MinGW32 and it worked.

If you run with some projects that use dynamic-link
and some other which use static-link, you will have to
keep your librairies in two different folders knowing that
“libSDL2main.a” will be in those two.

Sorry for my writing, I’m not used to write in english.

Mike

Leave a Comment