How to 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 Linux.
Luckily gcc man page directed me to -m32 and -m64 option. These options generate code for a 32-bit or 64-bit environments.
=> 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 as follows
For 32 bit version:
$ gcc -m32 -o output32 hello.c
For 64 bit version :
$ gcc -m64 -o output64 hello.c
And output is :
$ ./output32
Output:
Long int size is 4 bytes long!
Now let us see 64 bit output:
$ ./output64
Long int size is 8 bytes long!
Sample code - hello.c:
#include <stdio.h>
int main(){
long z; printf("Long int size is %i bytes long!\n", sizeof(z)); return 0;
}
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in other helpful articles:
- FreeBSD > Compiling application with QT
- How do I run 32bit application under itanium (ia64) system running RedHat Linux?
- Critical Linux security API is still a kludge
- Linux: How to compile program
- Kick start writing C/C++ and Java applications on Red Hat and SUSE Linux
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!


I think
gcc -m32 -o output64 hello.c
should be
!
gcc -m32 -o output32 hello.c
and
$ gcc -m64 -o output64 hello.c
should be
$ gcc -m64 -o output64 hello.c
mojo
Thanks for heads up!
its working . thx
I got this error trying to compile with -m32 :S
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h
Whats wrong?