Compiling/testing in 32-bit on Ubuntu X86-64

December 2016

If one has the need to devise a source code for either testing or using it in a form or a binary of the value 32-bit, a library of binary 32 bits is required in Ubuntu. Some packages in these operating systems have to be implemented in this case so that the command works. Install a multilib function to ensure that a library of binary 32 bits is available. After this is done, append -m32 to the code so that it works. Once these steps are followed in Ubuntu, one can use the program for standard functions. For using other libraries, it should be ensured that it's in sync with 32-bit.

If you want to compile a source code for testing purposes or to use it as a 32-bit binary, the main problem is that the headers of the standard library are not suitable for this purpose and that a version of the standard library in 32 bits is needed (specific gcc library compiled in 32 bits).

To install these packages, type this command:
sudo apt-get install gcc-multilib libc6-i386 lib6-dev-i386


To compile your program so we just attach the-m32:

gcc -m32 test.c -o test


This will be enough for a simple program using only the standard library but for programs using other libraries, all these libraries must be compiled in 32-bit too.

Related :

This document entitled « Compiling/testing in 32-bit on Ubuntu X86-64 » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.