N00B. If I compile a simple Hello World! program on a 64bit linux, will it work on a 32bit linux? (I'm using gcc).

#include <stdio.h>

int main(void)
{
	printf("Hello World!");
	return 0;
}

Recommended Answers

All 5 Replies

>> If I compile a simple Hello World! program on a 64bit linux, will it work on a 32bit linux?

Depends on the flags you give the compiler. The default is to produce 32-bit code, but you can tell it to produce 64-bit code. Just because you are running a 64-bit operating system doesn't mean the compiler will automatically produce 64-bit code.

If you installed a 64 bit version of Linux on a 64 bit box, then the default compiler(gcc) will produce 64 bit code...that is unless you set the appro. switches telling it to produce 32 bit code...

If you want to run the program with the 32 bit compiler include -m32 in your compiler option

If you want to run the program with the 32 bit compiler include -m32 in your compiler option

1. Can I compile a single program than runs on both 32 and 64?

2. I have a 64bit Debian Linux and tried to compile using -m32 but returned error. I'm probably missing some package. Any ideas?

raigs@mycomputer:~/Desktop$ gcc -m32 pig.c
In file included from /usr/include/features.h:361,
                 from /usr/include/stdio.h:28,
                 from pig.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
raigs@mycomputer:~/Desktop$

1. Can I compile a single program than runs on both 32 and 64?

2. I have a 64bit Debian Linux and tried to compile using -m32 but returned error. I'm probably missing some package. Any ideas?

raigs@mycomputer:~/Desktop$ gcc -m32 pig.c
In file included from /usr/include/features.h:361,
                 from /usr/include/stdio.h:28,
                 from pig.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
raigs@mycomputer:~/Desktop$

There are diffrent compiler options for 32 bit and 64 bit in diffrent platforms.
You can get more detail about that in the below link.
http://www.openlinksw.com/dataspace/dav/wiki/Main/VOSMake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.