Need help buildling SDL_mixer for MinGW on Linux

I’ve downloaded the latest mingw releases for SDL, SDL_image, and SDL_mixer on Github and have been able to use them to compile my game on Linux for Windows. Just recently I added MOD music to my game which has worked fine on Linux (compiled with Debian’s SDL dev packages) but fails on Windows because the latest SDL_mixer release was compiled without MOD support. When running the game, I get a single SDL error message: “MOD support not available”.

I tried to build SDL_mixer myself with MOD support but to no avail. I was able to compile the library for Linux with the steps from https://wiki.libsdl.org/SDL2/Installation but I haven’t been able to compile the library for use with 32-bit mingw.

So far I have tried running “…/configure --host=mingw64” from the build directory in the SDL_mixer root directory, but that just creates a Makefile that compiles files with gcc (instead of mingw, so I think that’s wrong), and eventually fails with this message:

libtool: compile:  gcc -g -O2 -I../include -I../src -I../src/codecs -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL2 -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=6 -DSDL_BUILD_MICRO_VERSION=2 -Wall -DHAVE_SIGNAL_H -DHAVE_SETBUF -DHAVE_FORK -DMUSIC_CMD -DMUSIC_WAV -DMUSIC_MOD_MODPLUG -DMUSIC_MID -DMUSIC_MID_TIMIDITY -I../src/codecs/timidity -DMUSIC_MID_NATIVE -I../src/codecs/native_midi -DMUSIC_OGG -DOGG_USE_STB -DMUSIC_FLAC_DRFLAC -DMUSIC_MP3_DRMP3 -MMD -MT build/native_midi_win32.lo -c ../src/codecs/native_midi/native_midi_win32.c -o build/native_midi_win32.o >/dev/null 2>&1
/bin/bash ./libtool --tag=RC --mode=compile  ../version.rc -o build/version.lo
libtool: compile: you must specify a compilation command
libtool: compile: Try `libtool --help --mode=compile' for more information.
make: *** [Makefile:252: build/version.lo] Error 1

tl;dr how can I build SDL_mixer for MinGW on Linux with MOD support?

do you tried to set the compiler?
maybe this cmd can do the thing:
install mingw on your system:
sudo apt install wine mingw-w64-x86-64-dev mingw-w64-i686-dev
Set the compiler and try to compile:
CC=i686-mingw32-gcc ./configure
NOTE: untested cmd
NOTE2: maybe you should pass the -static-libgcc as param to the compilation.

Are you testing games with Wine?

I’ve changed the environment variables and recompiled like so:

mkdir build
cd build
export CC="i686-w64-mingw32-gcc"
export CXX="i686-w64-mingw32-g++"
../configure --host=mingw64

But that causes this error:

/bin/bash ../build-scripts//mkinstalldirs build
mkdir -p -- build
touch build/.created
/bin/bash ./libtool --mode=compile i686-w64-mingw32-gcc -g -O2  -I../include -I../src -I../src/codecs -D_GNU_SOURCE=1
-D_REENTRANT -I/usr/include/SDL2 -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=6 -DSDL_BUILD_MICRO_VERSION=2 -Wall -DHAVE_SIGNAL_H -DHAVE_SETBUF -DMUSIC_WAV -DMUSIC_MOD_MODPLUG  -DMUSIC_MID -DMUSIC_MID_TIMIDITY -I../src/codecs/timidity -DMUSIC_MID_NATIVE -I../src/codecs/native_midi -DMUSIC_OGG -DOGG_USE_STB -DMUSIC_FLAC_DRFLAC -DMUSIC_MP3_DRMP3 -MMD -MT build/load_aiff.lo -c ../src/codecs/load_aiff.c -o build/load_aiff.lo
libtool: compile:  i686-w64-mingw32-gcc -g -O2 -I../include -I../src -I../src/codecs -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL2 -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=6 -DSDL_BUILD_MICRO_VERSION=2 -Wall -DHAVE_SIGNAL_H -DHAVE_SETBUF -DMUSIC_WAV -DMUSIC_MOD_MODPLUG -DMUSIC_MID -DMUSIC_MID_TIMIDITY -I../src/codecs/timidity -DMUSIC_MID_NATIVE -I../src/codecs/native_midi -DMUSIC_OGG -DOGG_USE_STB -DMUSIC_FLAC_DRFLAC -DMUSIC_MP3_DRMP3 -MMD -MT build/load_aiff.lo -c ../src/codecs/load_aiff.c  -DDLL_EXPORT -DPIC -o build/.libs/load_aiff.o
In file included from /usr/include/SDL2/SDL_stdinc.h:31,
                 from /usr/include/SDL2/SDL_endian.h:31,
                 from ../src/codecs/load_aiff.c:31:
/usr/include/SDL2/SDL_config.h:4:10: fatal error: SDL2/_real_SDL_config.h: No such file or directory
    4 | #include <SDL2/_real_SDL_config.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:181: build/load_aiff.lo] Error 1

Even if I had the right header files to avoid this error, I still think the Makefile would be wrong because it seems to be building .lo files, which, correct me if I’m wrong, but I think those are only for Linux and not Windows.

I’m not sure how to pass -static-libgcc as a parameter.

I’ve tested with both Wine and Windows 10. Both show the same error message: “MOD support not available”

I’m not sure this will help, because I disabled MOD (I never need it yet on my set) but I just cross compiled SDL2-mixer 2.06 on Linux using mingw32-w64

In fact, SDL2-mixer uses cmake, and using a working script, I was able to complete the build easely, install it and make playmusic.exe and playwave.exe to work WITHOUT MOD (-D SDL2MIXER_MOD=OFF is the right option to disable MOD)

You’ll probably have to cross-compile libmod and install it, and follow the model I propose. All information stands in the CMakeFile, you’ll have to read carefully. If I’m not too wrong, you’ll have to choose one mixer at least + dependencies.

First, the script:

#!/bin/bash

export MINGW_PATH=/usr/local/cross-tools/x86_64-w64-mingw32/

cmake   -B build_win64 \
        -D CMAKE_INSTALL_PREFIX=${MINGW_PATH} \
        -D SDL2_LIBRARY=${MINGW_PATH}/lib/libSDL2.dll.a \
        -D SDL2_INCLUDE_DIR=${MINGW_PATH}/include/SDL2/ \
        -D SDL2_MAIN_LIBRARY=${MINGW_PATH}/lib/libSDL2main.a \
        -D SDL2MIXER_OPUS=OFF \
        -D SDL2MIXER_MOD=OFF \
        -D SDL2MIXER_MIDI=OFF \
        -D SDL2MIXER_FLAC=ON \
        -D FLAC_INCLUDE_PATH=/usr/local/cross-tools/x86_64-w64-mingw32/include \
        -D FLAC_LIBRARY=/usr/local/cross-tools/x86_64-w64-mingw32/lib \
        -D BUILD_SHARED_LIBS=NO \
        -D CMAKE_TOOLCHAIN_FILE=toolchain-LinuxMint-mingw64.cmake \
        .


# + extra ressources, very helpfull :
# https://stackoverflow.com/questions/28260245/receiving-undefined-references-to-various-windows-libraries-when-compiling-with

Second, you’ll have to copy paste the content below in a file named “toolchain-LinuxMint-mingw64.cmake”

# LinuxMint toolchain from Linux to Windows  mingw32-w64
# Eric Bachard // May 22nd 2017 License GPL v2

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_INSTALL_PREFIX /usr/local/cross-tools/x86_64-w64-mingw32)
set(CMAKE_C_COMPILER_WORKS 1)

set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(DBUILD_SHARED_LIBS OFF)

# target environment on the build host system
#   set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Disclaimer : I linked to libSDL2.dll.a instead of libSDL2.a because I was missing some windows libraries to link to (e.g. namely Ole32, Oleaut32, Imm32, Winmm and other) and I had not much time.

For lazy people, the other solution is to download everything from the following link:

And if something is wrong, feel free to correct and explain me !

I hope this will help someone.

P.S. : FYI, I was unable to login with my normal brower, because of discourse saying my browser was outdated, only tor was able to display the login. Not very kind :-/

1 Like

I don’t know much about cross-compilation, but you can use my mixer instead of SDL_mixer, or write your own and use e.g. micromod…

I modified the script and toolchain like so:

#!/bin/bash

rm -rf build_win32

export MINGW_PATH=/home/cata/projects/windev

cmake   -B build_win32 \
        -D CMAKE_INSTALL_PREFIX=${MINGW_PATH} \
        -D SDL2_INCLUDE_DIR=${MINGW_PATH}/include/SDL2/ \
        -D SDL2_MAIN_LIBRARY=${MINGW_PATH}/lib/libSDL2main.a \
        -D SDL2MIXER_OPUS=OFF \
        -D SDL2MIXER_MOD=ON \
        -D SDL2MIXER_MIDI=OFF \
        -D SDL2MIXER_FLAC=OFF \
	-D SDL2MIXER_MOD_MODPLUG=ON \
	-D SDL2MIXER_MOD_MODPLUG_SHARED=OFF \
        -D BUILD_SHARED_LIBS=NO \
        -D CMAKE_TOOLCHAIN_FILE=${MINGW_PATH}/cmake/toolchain-Debian-mingw32.cmake \
        .
# LinuxMint toolchain from Linux to Windows  mingw32-w64
# Eric Bachard // May 22nd 2017 License GPL v2

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_INSTALL_PREFIX /home/cata/projects/windev)
set(CMAKE_C_COMPILER_WORKS 1)

set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(DBUILD_SHARED_LIBS OFF)

# target environment on the build host system
#   set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /home/cata/projects/windev)

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

And I was able to successfully build SDL_mixer, though the playmus example built by cmake didn’t work. When running it in wine I got this error:

0024:err:module:import_dll Library libmodplug.dll (which is needed by L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\playmus.exe") not found
0024:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\playmus.exe" failed, status c0000135

It seems to have built the programs with dynamic linking for libmodplug, which isn’t what I intended. Furthermore, even with libmodplug.dll in the same directory, the program fails when trying to find dlls for libgcc and libstdc++

0024:err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\libmodplug.dll") not found
0024:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\libmodplug.dll") not found
0024:err:module:import_dll Library libmodplug.dll (which is needed by L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\playmus.exe") not found
0024:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\cata\\projects\\windev\\downloads\\SDL_mixer-release-2.6.2\\build_win32\\playmus.exe" failed, status c0000135

The libgcc and libstdc++ linking problem might be a libmodplug issue, but I’m pretty sure the failure to statically link against libmodplug for SDL_mixer is a mixer build issue.

Were you able to statically link against your FLAC codec library when building SDL_mixer, and if so how?