Skip to content

Instantly share code, notes, and snippets.

@HerrPi
Last active January 18, 2023 12:09
Show Gist options
  • Save HerrPi/be902ecef27295627671552bde43d180 to your computer and use it in GitHub Desktop.
Save HerrPi/be902ecef27295627671552bde43d180 to your computer and use it in GitHub Desktop.
MINGW64: Build a static SoX (.exe) for Windows, DLL-independent with MP3 de-/encoding support (libmad and Lame encoder)

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.

Goal

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.

Prerequisites

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

Lame Encoder

Build Lame

./configure --prefix=/mingw64 --enable-static --disable-shared --disable-frontend
make
make install

libmad

Necessary patches / fixes

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

Build libmad

./configure --prefix=/mingw64 --enable-static --disable-shared
make
make install

SoX

Build SoX

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

Strip final executable

If you wanna lose about 1/3 of the file size, you can strip afterwards! :-)

strip /mingw64/bin/sox.exe
#!/bin/sh
COMMON_ARGS="--prefix=/mingw64 --enable-static --disable-shared"
LAME_ARGS="--disable-frontend"
SOX_ARGS="--disable-openmp --without-magic --without-png --without-ladspa --without-gsm --without-lpc10 --without-oss --with-mad --with-lame"
tar xf lame-3.100.tar.gz
cd lame-3.100
./configure $COMMON_ARGS $LAME_ARGS
make
make install
cd ..
tar xf libmad-0.15.1b.tar.gz
cd libmad-0.15.1b
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 $COMMON_ARGS
make
make install
cd ..
tar xf sox-14.4.2.tar.gz
cd sox-14.4.2
patch -Np1 -i ../sox-gdve-build.patch
./configure $COMMON_ARGS $SOX_ARGS
make
make install
strip /mingw64/bin/sox.exe
--- sox-14.4.2-orig/src/sox.c 2014-10-06 04:02:30.000000000 +0200
+++ sox-14.4.2/src/sox.c 2023-01-18 12:54:05.831594500 +0100
@@ -1821,8 +1821,9 @@
#endif
const sox_version_info_t* info = sox_version_info();
- fprintf(file, "%s: SoX v%s%s%s\n",
+ fprintf(file, "%s: SoX GdvE Build (%s %s) v%s%s%s\n",
myname,
+ __DATE__, __TIME__,
info->version,
info->version_extra ? "-" : "",
info->version_extra ? info->version_extra : "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment