How to statically link SDL.dll into your application
This post will show you how to statically link libSDL.a into your application instead of dynamically link with SDL.dll
This post uses ffmpeg as an example, cross-compiled on linux with mingw32 compiler, which I think is a good complex example and useful example.
Prerequisite : Linux Debian or Ubuntu (or other Debian derived distributions, example mint)
Step 1 - Install gcc mingw cross-compiler
sudo apt-get install gcc-mingw-w64
This installs the cross-compiler
Step 2 - Download files needed
(1) Download SDL source code and the two cross-configure.sh and cross-make.sh scripts:
https://www.libsdl.org/release/SDL-1.2.15.tar.gz
http://www.libsdl.org/extras/win32/cross/cross-configure.sh
http://www.libsdl.org/extras/win32/cross/cross-make.sh
(2) Extract this to a folder in your home directory.
(3) Run this to cross-compile SDL 1.2.15 in a 32-bit library.
./cross-configure.sh
./cross-make.sh
sudo ./cross-make.sh install
(4) To then build the 64-bit library, edit cross-configure.sh and cross-make.sh by substituting i686 for x86_64 (only one place in each file) :
Change TARGET=i686-w64-mingw32
to
TARGET=x86_64-w64-mingw32
(5) Run this to cross-compile SDL 1.2.15 in a 64-bit library.
./cross-configure.sh
./cross-make.sh
sudo ./cross-make.sh install
Step 3 : Building ffmpeg
Download ffmpeg source code
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg.git
For 64-bit compilation :
export PKG_CONFIG_PATH="/usr/local/cross-tools/x86_64-w64-mingw32/lib/pkgconfig"
./configure --enable-memalign-hack --arch=x86_64 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --disable-shared --pkg-config=pkg-config --enable-gpl --enable-swscale
make
For 32-bit compilation :
export PKG_CONFIG_PATH="/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig"
./configure --enable-memalign-hack --arch=i686 --target-os=mingw32 --cross-prefix=i686-w64-mingw32- --disable-shared --pkg-config=pkg-config --enable-gpl --enable-swscale
make
Optional : Statically link SDL
Edit config.mak for static linking of SDL
Note: This works very well for 64-bit compilation of ffplay. I don't know why I haven't been able for 32-bit.
Add the things in bold.
LIBS-ffplay=-mwindows -L/usr/local/cross-tools/x86_64-w64-mingw32/lib -lmingw32 -Wl,-Bstatic -lSDLmain -Wl,-Bstatic -lSDL -lwinmm -lgdi32 -ldxguid
(...)
EXTRALIBS=-lavicap32 -lpsapi -lole32 -lstrmiids -luuid -lws2_32 -mwindows -L/usr/local/cross-tools/x86_64-w64-mingw32/lib -lmingw32 -Wl,-Bstatic -lSDLmain -Wl,-Bstatic -lSDL -lm -lpsapi -ladvapi32 -lshell32 -lwinmm -lgdi32 -ldxguid
Recent Comments