User guide

Running GCC
49
$ file hello64
hello64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked
(uses shared libs), for GNU/Linux 2.6.18, not stripped
$ ldd hello64
linux-vdso.so.1 => (0x00007fff242dd000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0721514000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0721893000)
The command file on a 64-bit executable will include ELF 64-bit in its output, and ldd will
list /lib64/libc.so.6 as the main C library linked.
3. On a 64-bit system, compile hello.c into a 32-bit executable with:
gcc -m32 hello.c -o hello32
4. Ensure that the resulting executable is a 32-bit binary:
$ file hello32
hello32: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically
linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
$ ldd hello32
linux-gate.so.1 => (0x007eb000)
libc.so.6 => /lib/libc.so.6 (0x00b13000)
/lib/ld-linux.so.2 (0x00cd7000)
The command file on a 32-bit executable will include ELF 32-bit in its output, and ldd will
list /lib/libc.so.6 as the main C library linked.
If you have not installed the 32-bit supporting libraries you will get an error similar to this for C code:
$ gcc -m32 hello32.c -o hello32
/usr/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status
A similar error would be triggered on C++ code:
$ g++ -m32 hello32.cc -o hello32-c++
In file included from /usr/include/features.h:385,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/x86_64-redhat-
linux/32/bits/os_defines.h:39,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/x86_64-redhat-
linux/32/bits/c++config.h:243,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/iostream:39,
from hello32.cc:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
These errors indicate that the supporting 32-bit libraries have not been properly installed as explained
at the beginning of this section.
It is important to note that even if 32-bit binaries can run on 64-bit systems, it is preferrable to have
64-bit binaries unless otherwise needed. In order to run 32-bit binaries on 64-bit systems, the system
must import additional 32-bit shared libraries that must be loaded in tandem with the 64-bit libraries
(for example glibc). This causes additional memory usage on such systems. It is always preferrable to
have 64-bit binaries for 64-bit systems and 32-bit binaries for 32-bit systems.