Develop on Linux 64-bit
Jump to navigation
Jump to search
Building for i386 target on amd64
This chapter explains how to build 32-bit applications on 64-bit GNU/Linux (Ubuntu, Debian).
References:
- How to compile a 32-bit application using gcc on the 64-bit Linux version
- Running 32-bit Applications on 64-bit Debian GNU/Linux
- Using proprietary i386 apps on an amd64 system
- Install the basic 32-bit libraries
- Install the package ia32-libs, which contains a basic set of 32-bit libraries (only console applications and basic X and GTK applications).
- Optionally install also the package ia32-libs-gtk to get some extra 32-bit GTK (GIMP ToolKit) libraries.
sudo apt-get install ia32-libs
sudo apt-get install ia32-libs-gtk # optional
- Compilation and linking
- With gcc, use the flag
-m32
both for compilation and linking:
gcc -m32 -o output32 hello.c
- Find which dynamic libraries are needed with ldd
- Find out which dynamic libraries are needed by the executables. If these libraries are not in the basic set of 32-bit libraries installed above, they'll have to be installed manually.
ldd output32
Applications using java (openjdk)
The .java can be compiled with whatever version (32-bit or 64-bit). However native applications targetting the i386 platform must be compiled and linked against the 32-bit versions of the java libraries.
- Get the java 32-bit libraries
- To get the libraries, the easiest is to copy them from a 32-bit linux machine. Copy the jre/ directory to say /usr/lib32/jre on the 64-bit machine:
#For instance, for java-6-openjdk
sudo mkdir -p /usr/lib32/jvm
sudo cp -r .../java-6-openjdk /usr/lib32/jvm
- Alternatively these libraries can be extracted from package (e.g. package openjdk-6-jre-headless, copy directory /usr/lib/jvm/java-6-openjdk)
- Compile and link against the 32-bit libraries
#Compile
gcc -m32 -I $(NFC4JAVA_JDKBASE)/include -I $(NFC4JAVA_JDKBASE)/include/linux -o ... -c ...
#Link
gcc -m32 -Wl,-rpath,/usr/lib32/jre/lib/i386/client -L /usr/lib32/jre/lib/i386/client -ljvm -o ... ...
Other solutions
- Using chroot
- Install a complete 32-bit build system in a chroot directory
- Using a Virtual Environment
- Such as VirtualBox or QEmu