MINGW64: Build a static SoX (.exe) for Windows, DLL-independent with MP3 de-/encoding support (libmad and Lame encoder)
Here are my personal notes on compiling SoX with MINGW64. Maybe, my situation isn't representative for everyone. Or maybe, I could have achieved my goal easier. But this is the way I succeeded.
I need to build SoX as a static .exe file with MP3 de- and encoding support, to be able to normalize an existing MP3 file and save it as MP3.
I used Windows 11 Pro and MINGW64. I did another successful test with Windows 8.1.
My main goal is to be able to normalize and save back MP3 files. So I need SoX for normalization and libmad / Lame for MP3 de-/encoding. At best, I would like to port my target .exe file to other systems without the need of any depending DLL or other file.
- MSYS2 (https://www.msys2.org)
- SoX 14.4.2 (https://sourceforge.net/projects/sox/files/sox/14.4.2/sox-14.4.2.tar.gz/download)
- libmad 0.15.1b (https://sourceforge.net/projects/mad/files/libmad/0.15.1b/libmad-0.15.1b.tar.gz/download)
- Lame 3.100 (https://sourceforge.net/projects/lame/files/lame/3.100/lame-3.100.tar.gz/download)
Start MSYS2 MINGW64 from the Windows Start Menu.
System update:
pacman -Syu
Install necessary build tools:
pacman -S gcc make patch autotools
Install toolchain for independent Windows exe:
pacman -S mingw-w64-x86_64-toolchain
./configure --prefix=/mingw64 --enable-static --disable-shared --disable-frontend
make
make install
patch -Np1 -i ../libmad-0.15.1b-fixes-1.patch
sed "s@AM_CONFIG_HEADER@AC_CONFIG_HEADERS@g" -i configure.ac
touch NEWS AUTHORS ChangeLog
autoreconf -fvi
./configure --prefix=/mingw64 --enable-static --disable-shared
make
make install
The options are just my personal preference. You can change them to whatever you like or dislike. Only the "--with-mad" and "--with-lame" are required.
./configure --prefix=/mingw64 --enable-static --disable-shared --disable-openmp --without-magic --without-png --without-ladspa --without-gsm --without-lpc10 --without-oss --with-mad --with-lame
make
make install
If you wanna lose about 1/3 of the file size, you can strip afterwards! :-)
strip /mingw64/bin/sox.exe