Search This Blog

Tuesday, October 25, 2011

Check 32 and 64 bits compatibility on 64bits Kernel

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 2.6.37.1-1.2-desktop #1 SMP PREEMPT 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux

Or something a little more standard...

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

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

alvaro@linux-a77o:~> cat test-bits.c #include 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 these 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 installing or configuring 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!