Cross compiling SDL x86 on x86_64 for Linux platform

Hello!

I’ve been attempting at compiling libSDL2 (2.30) targeting Linux x86 32-bit from x86_64 platform without any success. My compiling environment is a Debian 9 stretch (x86_64) schroot on Debian 12 bookworm host.

From both autoconf and CMake I get some issue regarding glib-2.0 header and ibus:

In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9:0,
                 from /usr/include/glib-2.0/glib/gtypes.h:32,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /usr/include/ibus-1.0/ibusshare.h:39,
                 from /usr/include/ibus-1.0/ibus.h:29,
                 from /[redacted]/SDL2-2.30.1/src/core/linux/SDL_ibus.h:30,
                 from /[redacted]/SDL2-2.30.1/src/core/linux/SDL_ime.c:24:
/usr/include/glib-2.0/glib/gtypes.h: In function ‘_GLIB_CHECKED_ADD_U64’:
/usr/include/glib-2.0/glib/gtypes.h:423:3: error: size of array ‘_GStaticAssertCompileTimeAssertion_0’ is negative
   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
   ^

One thing I noticed is that this is using x86_64 include path, don’t know if this is expected when using gcc-multilib.

Here’s my script used for compiling:

#!/usr/bin/env bash

DFLAGS="-g -ggdb -ggdb3"
USER_FLAGS="-pipe -w"
OPTFLAGS="-O2"

ARCH="i686"
ARCH_FLAGS="-m32 -march=${ARCH} ${OPTFLAGS}"
BUILD="${ARCH}-pc-linux-gnu"
LDFLAGS="-shared -m32"

export CFLAGS="${DFLAGS} ${USER_FLAGS} ${ARCH_FLAGS}"
CMAKE_C_FLAGS="${CMAKE_C_FLAGS} ${CFLAGS}"

rm -R build_cmake
mkdir build_cmake
cd build_cmake
cmake .. \
-DSDL_ALSA=ON \
-DSDL_ALSA_SHARED=OFF \
-DSDL_ARTS=OFF \
-DSDL_COCOA=OFF \
-DSDL_DBUS=ON \
-DSDL_DIRECTFB=OFF \
-DSDL_DIRECTX=OFF \
-DSDL_ESD=OFF \
-DSDL_FUSIONSOUND=OFF \
-DSDL_HIDAPI=ON \
-DSDL_HIDAPI_JOYSTICK=ON \
-DSDL_IBUS=ON \
-DSDL_JACK=OFF \
-DSDL_JOYSTICK_MFI=OFF \
-DSDL_KMSDRM=OFF \
-DSDL_LIBSAMPLERATE=ON \
-DSDL_LIBSAMPLERATE_SHARED=OFF \
-DSDL_LIBUDEV=ON \
-DSDL_METAL=OFF \
-DSDL_NAS=OFF \
-DSDL_OPENGL=ON \
-DSDL_OPENGLES=ON \
-DSDL_PIPEWIRE=ON \
-DSDL_PULSEAUDIO=ON \
-DSDL_PULSEAUDIO_SHARED=OFF \
-DSDL_RENDER_D3D=OFF \
-DSDL_RPATH=OFF \
-DSDL_RPI=OFF \
-DSDL_SHARED=ON \
-DSDL_SNDIO=OFF \
-DSDL_SSE2=ON \
-DSDL_SSE3=ON \
-DSDL_STATIC=OFF \
-DSDL_TEST=OFF \
-DSDL_VIVANTE=OFF \
-DSDL_VULKAN=ON \
-DSDL_WASAPI=OFF \
-DSDL_WAYLAND=ON \
-DSDL_WAYLAND_LIBDECOR=ON \
-DSDL_WAYLAND_SHARED=OFF \
-DSDL_X11=ON \
-DSDL_X11_SHARED=OFF \
-DSDL_XINPUT=OFF \
-DSDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS=1

make -j14

Would I need a pure x86 32-bit chroot environment for compiling or am I missing something here?

Thanks!

Let me know if this helps: → Building SDL2 for 32-bit on a 64-bit Linux

I use docker to accomplish that and it comes with the bonus that I can run tests on it too right after building. I use a x86 debian as my docker base.

Thanks for replying. Unfortunately that was something I tried initially with autoconf, before going with cmake route which gave same result.

At the configuration stage I see:

checking for ibus-1.0... yes
checking ibus-1.0/ibus.h usability... no
checking ibus-1.0/ibus.h presence... yes
configure: WARNING: ibus-1.0/ibus.h: present but cannot be compiled
configure: WARNING: ibus-1.0/ibus.h:     check for missing prerequisite headers?
configure: WARNING: ibus-1.0/ibus.h: see the Autoconf documentation
configure: WARNING: ibus-1.0/ibus.h:     section "Present But Cannot Be Compiled"
configure: WARNING: ibus-1.0/ibus.h: proceeding with the compiler's result
checking for ibus-1.0/ibus.h... no

config.log shows:

configure:24686: checking for ibus-1.0
configure:24693: $PKG_CONFIG --exists --print-errors "ibus-1.0"
configure:24696: $? = 0
configure:24710: $PKG_CONFIG --exists --print-errors "ibus-1.0"
configure:24713: $? = 0
configure:24751: result: yes
configure:24757: checking ibus-1.0/ibus.h usability
configure:24757: gcc -c -m32 -Iinclude -ISDL2-2.30.1/include -idirafter SDL2-2.30.1/src/video/khronos   -Iinclude -ISDL2-2.30.1/include -idirafter SDL2-2.30.1/src/video/khronos  -pthread -I/usr/include/ibus-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include conftest.c >&5
In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9:0,
                 from /usr/include/glib-2.0/glib/gtypes.h:32,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /usr/include/ibus-1.0/ibusshare.h:39,
                 from /usr/include/ibus-1.0/ibus.h:29,
                 from conftest.c:209:
/usr/include/glib-2.0/glib/gtypes.h: In function '_GLIB_CHECKED_ADD_U64':
/usr/include/glib-2.0/glib/gtypes.h:423:3: error: size of array '_GStaticAssertCompileTimeAssertion_0' is negative
   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
   ^
configure:24757: $? = 1

I ended up going with a pure x86 32-bit chroot environment which worked. I still wanted to understand why this was failing as I’ve never had something similar to this issue when compiling other projects targeting 32-bit system on a x64 environment.