i686

Method to compile 32bit programs on 64bit Linux CentOS 7

The method recorded here theoretically applies to all RedHat‑based Linux distributions!
Normally on 64bit Linux (after installing gcc and related tools), compiled executables target the 64bit environment. If you want to compile for 32bit (which can also run on 64bit systems), just add the -m32 option to gcc (for ld there is a corresponding -melf_i386). Although compiling only requires adding the parameter, you still need to install the 32bit versions of the C and C++ standard libraries.

For example, if you compile directly with -m32, you will get the following error:

[kres@localhost test6432]$ gcc -m32 test.c
In file included from /usr/include/features.h:399:0,
from /usr/include/unistd.h:25,
from /usr/include/usb.h:28,
from test.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h:No such file or directory

# include ;
^
compilation terminated.
Continue reading…