Strange configure issue with SDL 2.26.0 and MinGW
When compiling master (cc2b61c0) under Windows 10 via MinGW in accordance with:
https://gitlab.com/Tapani_/1oom/-/blob/cc2b61c04c9bd11e17b06dc7b8d7c84760159842/INSTALL#L82
I ran into an issue where the configure script could not locate SDL2_mixer.
It almost seems like this an oversight with SDL2 itself, though the guide is 3 years old so it's possible that something changed with more recent releases and that the guide needs updating.
To clarify how SDL is to be handled for MinGW:
- Ensure that the
mingw32-base-bin
andmsys-base-bin
packages are installed within the MinGW Installation Manager - Start
MINGW_PATH\msys\1.0\bin\sh
- Add
MINGW_PATH\bin
andMINGW_PATH\msys\1.0\bin
to the PATH environment variable - Download the latest (at this time of writing) MinGW specific SDL2 and SDL2_mixer packages
- Extract both packages, and then for both, within the
sh
sessioncd
into them and runmake native
Then as the guide states, try to configure a build for the repo:
cd 1oom
mkdir build-native
cd build-native
../configure --disable-hwsdl1 --disable-hwalleg4 --disable-hwx11
CLARIFICATION: I don't do much building on Linux (and the amount I do is using CMake) so I know basically nothing about autoconf and its related tools. I discerned what's going on here via investigation and trial and error. As such my solution is more of a hotfix rather than a proper fix.
At this point the configuration will fail at the step "checking for the SDL2_mixer library..." with "configure: error: SDL2_mixer not found! Either install it or use --disable-hwsdl2audio to disable audio for the SDL2 binaries."
Inspecting config.log in the build directory reveals:
configure:6217: checking for the SDL2_mixer library
configure:6246: gcc -o conftest.exe -g -O3 -Wall -Wno-inline -Wstrict-prototypes -I/usr/include/SDL2 -Dmain=SDL_main conftest.c -lSDL2_mixer -lwinmm -L/opt/local/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid >&5
I don't fully understand the wizardry that actually sets this up, but the conftest that is failing gets the value for the SDL_mixer directories from SDL2_mixer.pc
which will be located in MINGW_PATH\msys\1.0\lib\pkgconfig
:
prefix=/opt/local/i686-w64-mingw32
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: SDL2_mixer
Description: mixer library for Simple DirectMedia Layer
Version: 2.6.2
Requires: sdl2 >= 2.0.9
Libs: -L${libdir} -lSDL2_mixer
Cflags: -I${includedir}/SDL2
Requires.private:
Libs.private: -lwinmm
Notice that the prefix
path here is the one used in the test. For whatever reason, even though SDL2_mixer's Makefile shows make native
setting prefix
to /usr
and despite the fact the package was correctly installed to /usr
(this equates to MINGW_PATH\msys\1.0
on your actual filesystem), this package config file doesn't get modified and still uses this other prefix instead of /usr
. I think this prefix is for if your installing SDL2_mixer for cross-compilation purposes, but not for a native install. The regular SDL2 MinGW package config file has the "correct" prefix of /usr
, which is why it's not affected.
I think the problem is that the SDL make script(s) should be modifying the package config file based on how you call make
, but aren't, so for whatever reason SDL's package config is hardcoded such that it only works with a regular install, and SDL_mixer's for cross-compiling.
You'd think fixing this would be as simple as changing prefix=/opt/local/i686-w64-mingw32
to prefix=/usr
, yet while it's close, it doesn't work. I don't know if it's because of some kind of caching mechanism with autoconf/conftest, but the test doesn't seem to like the fact that /usr
was already used in the link option in the previous test for SDL. So, if you just set the prefix to /usr
the test still fails, while checking config.log
shows that the -L
statement for the SDL_mixer gets dropped entirely (so effectively it's ignored). To get around this, you have to change the prefix to something other than /usr
, but that still ultimately points to that directory.
In my case I changed the line to prefix=/usr/lib/..
, which is functionally equivalent, yet syntactically different.
This allowed the test to find SDL_mixer and resultant in a successful complication of the project.
Just wanted to record this all here in case it helps someone else out, and so that I can refer to it in the future if needed.