Skip to main content

gnu/stubs-32.h: No such file or directory

While trying to compile for ia32 on x86-64 system, this happened:

$ gcc -m32 file.c -o file.exe
In file included from /usr/include/features.h:378,
                 from /usr/include/stdio.h:28,
                 from file.c:10:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
Hm, let's see where to get gnu/stubs-32.h from:
$ apt-file search gnu/stubs-32.h
libc6-dev-i386: /usr/include/gnu/stubs-32.h
However, installing libc6-dev-i386 was not enough:
$ gcc -m32 file.c -o file.exe
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libgcc.a \
                  when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libgcc.a \
                  when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: ld returned 1 exit status
Turns out we needed GCC Multilib support:
$ sudo apt-get install gcc-multilib
(installs gcc-multilib, depends on lib32gcc1 and libc6-dev-i386)

$ gcc -m32 file.c -o file.exe
$ file file.exe
file.exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), \
             dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped