HowTo Compile a 32-bit Application Using gcc On the 64-bit Linux Version
HowTo Compile a 32-bit Application Using gcc On the 64-bit Linux Version
I had to compile a 32-bit application using GNU gcc on the 64-bit version of Linux.
Luckily, gcc man page directed me to the '-m32' and '-m64' options. These options generate code for 32-bit or 64-bit environments, respectively.
- The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system.
- The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture.
You can pass -m64 or -m32 options as follows to Gnu gcc
For 32 bit version:
$ gcc -m32 -o output32 hello.c
For 64 bit version :
$ gcc -m64 -o output64 hello.c
Run it as follows:
$ ./output32
Output:
Long int size is 4 bytes long!
Now let us see 64 bit output:
$ ./output64
Long int size is 8 bytes long!
--
Comments
Post a Comment