Can't Compile SDL2 For 32-Bit on 64-Bit Ubuntu Using Arm GNU Toolchain

Background

I am trying to cross compile SDL2 using the Arm GNU Toolchain. My host is Ubuntu 22.04.3 LTS running on WSL and my target is a 32-bit Cortex-A7. I have successfully compiled and ran “Hello World” with this setup, so my next step is to compile “Hello World” while including SDL2. Here’s the file:

#include <stdio.h>
#include <SDL.h>
int main()
{
  printf("Hello SDL2");
  return 0;
}

Here is the command I am using:

<path-to-compilers>/arm-none-linux-gnueabihf-gcc -static hellosdl2.c -o hellosdl2 -I /usr/include/SDL2 -I /usr/include/i386-linux-gnu -DSDL_DISABLE_IMMINTRIN_H

I am able to avoid the classic "No such file SDL2.h" error message by including the install paths of the 64 and 32 bit versions of the SDL2. (Downloaded using apt-get install libsdl2-dev libsdl2-dev:i386) I am also able to avoid the error "immintrin.h: No such file or directory" by using the -DSDL_DISABLE_IMMINTRIN_H flag.

Problem:

I cannot resolve this error:

In file included from /usr/include/SDL2/SDL_stdinc.h:90,
                 from /usr/include/SDL2/SDL_main.h:25,
                 from /usr/include/SDL2/SDL.h:32,
                 from hellosdl2.c:2:
/usr/include/i386-linux-gnu/bits/mathcalls-helper-functions.h:20:40: error: ‘_Float128’ is not supported on this target
   20 | __MATHDECL_ALIAS (int, __fpclassify,, (_Mdouble_ __value), fpclassify)

It looks like the SDL2 library is configured to build for a 64-bit target, and the compiler keeps catching that. I believe I’m missing a flag or a dependency. I have perused the interwebs for information on compiling SDL2 on a 32-bit target but haven’t seen this situation anywhere.

It seems to be complaining about a float128 type, which has nothing directly to do with whether the target is 32 or 64-bit. With an ARM target, float128 is probably the type that would be implied by long double, but I wouldn’t have expected the SDL2 sources to be referencing that type anywhere.

You include x86 headers, of course there’s an error. Fix your include paths, mind sharing your build configuration/compiler cmdline.

Thank you both for your feedback.

You include x86 headers, of course there’s an error.

If I understand correctly, you’re suggesting I remove -I /usr/include/SDL2. Running my build command without this path results in fatal error: SDL.h: No such file or directory. When I installed the i386 version of SDL2 with apt-get, only a few files were created in /usr/include/i386-linux-gnu:

SDL_platform.h  _real_SDL_config.h  begin_code.h  close_code.h

Am I missing something?

As for my build configuration, I haven’t actually configured anything. All I have is that single build command. Maybe I’m missing something there?

Here is the full path to my compiler, in case that helps:
/usr/bin/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static hellosdl2.c -o hellosdl2 -I /usr/include/SDL2 -I /usr/include/i386-linux-gnu -DSDL_DISABLE_IMMINTRIN_H

I may have just figured it out–I went into _real_SDL_config.h and commented out line 56:

/* Comment this if you want to build without any C library requirements */
//#define HAVE_LIBC 1

I was able to compile and run my program. I may run into issues building my full project, but at least I’m a step closer :slight_smile:

You should have dedicated prefix to install libraries for cross-compiler, including the SDL. The SDL.h is platform-agnostic without any machine-specific generated code so this is OK (but not right) to include SDL from your system prefix, but the SDL does include different headers that could be not platform-agnostic at all (your case!). The real error is:

Wrong, probably unsafe, and does not work. Learn how to create your cross-compile environment first, or try Debian -- ARM Ports (armel packages).

Your workaround might be a solution, but you might face enormous amount of hard to debug errors.

Keep me posted if you need help, good luck!