Check 32 and 64 bits compatibility on 64bits Kernel

Submitted by alvaro.soto on Tue, 10/25/2011 - 23:37

First we need to check if we have a 64Bits Kernel running.
Some linux distros use a release file to save the version, codename, and other information

alvaro@linux-a77o:~> cat /etc/SuSE-release
openSUSE 11.4 (x86_64)
VERSION = 11.4
CODENAME = Celadon

Or check the system information using uname

alvaro@linux-a77o:~> uname -a
Linux linux-a77o #1 SMP PREEMPT 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux

Or something a little more standart...

alvaro@linux-a77o:~> perl -MConfig -e 'print $Config{longsize}*8 . "\n";'

With this code we are going to be testing system libraries and support.

alvaro@linux-a77o:~> cat test-bits.c

int main()
	long z; 
	printf("Long int size is %i bytes long!\n", sizeof(z)); 
	return 0;

Without the 32bits support, we can only compile the 64bits binary.
The 32bits compilation will show some fatal errors, like this one:

alvaro@linux-a77o:~> gcc -m64 -o output64 test-bits.c 
alvaro@linux-a77o:~> gcc -m32 -o output32 test-bits.c 
In file included from /usr/include/features.h:371:0,
                 from /usr/include/stdio.h:28,
                 from test-bits.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
compilation terminated.

In this example I used OpenSuSe, so this are the steps to solve the problem in this version:

  • Software Management ->
  • View ->
  • Patterns ->
  • Search "Base Technologies" and then "32-bit runtime Library" ->
  • Activate some or all the checkboxes (you maybe need the CD, DVD or ISO image).

After install or configure the 32bits library support, we successfully compile and execute the binaries.

alvaro@linux-a77o:~> source /etc/profile
alvaro@linux-a77o:~> rm output*
alvaro@linux-a77o:~> gcc -m32 -o output32 test-bits.c 
alvaro@linux-a77o:~> gcc -m64 -o output64 test-bits.c 
alvaro@linux-a77o:~> ./output32 
Long int size is 4 bytes long!
alvaro@linux-a77o:~> ./output64 
Long int size is 8 bytes long!