SDL2_mixer: Trouble Linking to Static mpg123 & fluidsynth Libs

I have built static libraries for mpg123 & fluidsynth on my Windows system (trying to reduce number of DLLs to distribute). However, the libraries are missing some symbols required by SDL2_mixer. In fluidsynth, this missing symbol is fluid_player_add_mem. In mpg123, it is mpg123_replace_reader_handle. The following is the configuration used with the output:

  ../SDL2_mixer-2.0.4/configure \
    --prefix=/mingw32 \
    --build=i686-w64-mingw32 \
    --host=i686-w64-mingw32 \
    --enable-shared \
    --enable-static \
    --disable-music-ogg-shared \
    --disable-music-flac-shared \
    --enable-music-mp3 \
    --disable-music-mp3-mad-gpl \
    --enable-music-mp3-mpg123 \
    --disable-music-mp3-mpg123-shared \
    --enable-music-opus \
    --disable-music-opus-shared \
    --disable-music-midi-fluidsynth-shared \
    --disable-music-mod-modplug-shared \
    CPPFLAGS="-DMODPLUG_STATIC" \
    OPUSFILE_LIBS="`pkg-config opusfile --libs --static`"
...
checking for fluidsynth.h... yes
checking for fluid_player_add_mem in -lfluidsynth... no
configure: WARNING: *** Unable to find FluidSynth library (http://www.fluidsynth.org/)
configure: WARNING: FluidSynth support disabled
checking vorbis/vorbisfile.h usability... yes
checking vorbis/vorbisfile.h presence... yes
checking for vorbis/vorbisfile.h... yes
checking for ov_open_callbacks in -lvorbisfile... yes
checking FLAC/export.h usability... yes
checking FLAC/export.h presence... yes
checking for FLAC/export.h... yes
checking for libflac so-name version >= 8... yes
checking FLAC/stream_decoder.h usability... yes
checking FLAC/stream_decoder.h presence... yes
checking for FLAC/stream_decoder.h... yes
checking for FLAC__stream_decoder_new in -lFLAC... no
checking mpg123.h usability... yes
checking mpg123.h presence... yes
checking for mpg123.h... yes
checking for mpg123_replace_reader_handle in -lmpg123... no
configure: WARNING: *** Unable to find mpg123 library (https://www.mpg123.de)
configure: WARNING: mpg123 support disabled
configure: WARNING: MP3 support disabled
...

I am not sure why the symbols are not defined in the static libraries & not sure if this is fixable from within SDL2_mixer configuration or if I have to go back & try to figure out if the static libs can be built with the symbols included. I am more concerned with having MP3 support, so solving the fluidsynth issue is not as important. I have not yet contacted fluidsynth & mpg123 devs, but plan to if this is beyond the scope of SDL.

Details of my system:

mpg123 build configuration:

  ../mpg123-1.25.11/configure \
    --prefix=/mingw32 \
    --build=i686-w64-mingw32 \
    --host=i686-w64-mingw32 \
    --enable-shared=no \
    --enable-static

fluidsynth build configuration:

    /mingw32/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=/mingw32 \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -Denable-portaudio=ON \
      -Denable-dbus=OFF \
      ../fluidsynth-2.0.5

Edit: Okay, I have discovered that I can disable fluidsynth & still get midi support through timidity. Also, strangely, by disabling fluidsynth support, the configure script is able to recognize mpg123_replace_reader_handle in mpg123. Not sure why fluidsynth support would interfere with that:

...
    --disable-music-opus-shared \
    --disable-music-midi-fluidsynth \
    --disable-music-mod-modplug-shared \
...
...
checking for MODPLUG... yes
checking vorbis/vorbisfile.h usability... yes
checking vorbis/vorbisfile.h presence... yes
checking for vorbis/vorbisfile.h... yes
checking for ov_open_callbacks in -lvorbisfile... yes
checking FLAC/export.h usability... yes
checking FLAC/export.h presence... yes
checking for FLAC/export.h... yes
checking for libflac so-name version >= 8... yes
checking FLAC/stream_decoder.h usability... yes
checking FLAC/stream_decoder.h presence... yes
checking for FLAC/stream_decoder.h... yes
checking for FLAC__stream_decoder_new in -lFLAC... no
checking mpg123.h usability... yes
checking mpg123.h presence... yes
checking for mpg123.h... yes
checking for mpg123_replace_reader_handle in -lmpg123... yes
checking for OPUSFILE... yes
...

Is this normal?

Edit: Just found out that shared library of mpg123 is being linked to. Going to try this again.

Edit: Okay, tried to link to static library & got same missing symbol mpg123_replace_reader_handle. So problem persists.

Edit: Just discovered that my libmpg123.a static library does define the symbol:

$ grep -r "mpg123_replace_reader_handle" /mingw32/lib/
Binary file /mingw32/lib/libmpg123.a matches

So, not sure why the configure script can’t find it. Here is the configure log:

...
configure:12821: checking for mpg123_replace_reader_handle in -lmpg123
configure:12846: i686-w64-mingw32-gcc -o conftest.exe -march=x86-64 -mtune=generic -O2 -pipe  -D_GNU_SOURCE=1   -D_GNU_SOURCE=1 -pipe  conftest.c -lmpg123   >&5
C:/Development/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.1.0/../../../../lib/libmpg123.a(compat.o):(.text+0xd6): undefined reference to `_imp__PathIsRelativeW@4'
C:/Development/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.1.0/../../../../lib/libmpg123.a(compat.o):(.text+0x1ee): undefined reference to `_imp__PathIsUNCW@4'
C:/Development/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.1.0/../../../../lib/libmpg123.a(compat.o):(.text+0x9ab): undefined reference to `_imp__PathCombineW@12'
collect2.exe: error: ld returned 1 exit status
configure:12846: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_SIGNAL_H 1
| #define HAVE_SETBUF 1
| /* end confdefs.h.  */
| 
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char mpg123_replace_reader_handle ();
| int
| main ()
| {
| return mpg123_replace_reader_handle ();
|   ;
|   return 0;
| }
configure:12855: result: no
configure:12882: WARNING: *** Unable to find mpg123 library (https://www.mpg123.de)
configure:12884: WARNING: mpg123 support disabled
configure:12892: WARNING: MP3 support disabled
...

Edit: I just looked more carefully at the log output & the problem is not undefined mpg123_replace_reader_handle, it is undefined _imp__* symbols. Which, as I understand it, are usually only defined in shared/dll libraries.

Edit: The _imp__* symbols are defined in -lshlwapi, but I’m having trouble linking to it for the tests. I tried adding LIBS="-lshlwapi" & adding -lshlwapi to mpg123’s pkg-config file. Neither worked.

Solved: Find my way around it with the following patch followed by re-running autoconf:

--- SDL2_mixer-2.0.4/configure.in.orig	2019-07-28 05:25:21.951574300 +0000
+++ SDL2_mixer-2.0.4/configure.in	2019-07-28 05:29:57.342891500 +0000
@@ -618,7 +618,7 @@
               [], [enable_music_mp3_mpg123_shared=yes])
 if test x$enable_music_mp3_mpg123 = xyes; then
     AC_CHECK_HEADER([mpg123.h], [have_mpg123_hdr=yes])
-    AC_CHECK_LIB([mpg123], [mpg123_replace_reader_handle], [have_mpg123_lib=yes])
+    AC_CHECK_LIB([mpg123], [mpg123_replace_reader_handle], [have_mpg123_lib=yes], [], [-lshlwapi])
     if test x$have_mpg123_hdr = xyes -a x$have_mpg123_lib = xyes; then
         have_libmpg123=yes
         case "$host" in

There were a lot more undefined symbols in the fluidsynth test, but I’m not going to worry about it right now. I’m more worried about having mp3 support.