Introduction
Nowadays the compiler comes with a default 64-bit version. Sometimes we need to compile and execute code into some 32 bit c compiler. In that time, we have to use this feature. But it would lead to a problem if someone wants to run their program as a 32-bit rather than 64-bit for testing or debugging purposes. Therefore, we must have knowledge about this.
First, we have to check the current target version of the GCC compiler. To check this, we have to type this command.
Compilers (64-Bit) for Linux:
The following companies provide 64-bit compilers for Linux.
1. GCC:
It provides C, C++ and Fortran compilers for AMD64 architecture-based systems running the Linux or the Sun Solaris operating systems. This application note, however, does not discuss GCC compilers for Sun Solaris; this discussion is limited to the discussion of GCC compilers for Linux. Different Linux distributions offer different versions of the GCC compilers.
This application note focuses on the recommended compilers for the following major Linux distributions:
- SuSE Linux Enterprise Server 8
- SuSE Linux Enterprise Server 9
- SuSE Linux Enterprise Server 10
- SuSE Linux 10.1
- SuSE Linux 10.2
GCC-V
Using built-in specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
………..
………..
………..
Hence the fourth line Target: x86_64-Linux-gnu confirms that we are running 64-bit GCC. Now in order to compile with 32-bit GCC, just add a flag -m32 in the command line of compiling the ‘C’ language program. For instance, to compile a file of geek.c through Linux terminal, you must write the following command with -m32 flag.
Sometimes, this command may generate some error like below. This indicates that the standard library of GCC is missing. In that situation, we have to install them.
In file included from test_c.c:1:0:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
#include<bits/libc-header-start.h>
^~~~~~
compilation terminated.
Now, to install the standard library for gcc, we have to write the following commands.
- sudo apt-get install GCC-multilib
- sudo apt-get install g++-multilib
- Intel: It provides C, C++ and Fortran compilers for EM64T and compatible architecture-based systems running the Linux operating systems. The current version (as of August 2007) is 10.0.
- PathScale: It provides C, C++ and Fortran compilers for AMD64 architecture-based systems running the Linux operating system. The current version (as of August 2007) is 3.0.
- PGI: The Portland Group (PGI) Toolkits are composed of high-performance C, C++ and/or Fortran Compiler(s), a debugger, and a performance profiler for 32-bit and 64-bit AMD64 and EM64T processor-based Linux. The latest PGI Edition 7 provides leading-edge application performance on AMD64 next-generation systems and supports features like auto-parallelization, OS-native multithreading, OpenMP multithreading models, and MPI programming for AMD64 architecture based multicore shared-memory and distributed-memory cluster-based systems.