Develop on Linux 64-bit: Difference between revisions
Jump to navigation
Jump to search
(Created page with '== Building for i386 target on amd64 == This chapter explains how to build 32-bit applications on 64-bit GNU/Linux (Ubuntu, Debian). References: * [http://www.cyberciti.biz/tips…') |
|||
Line 19: | Line 19: | ||
<source lang="bash"> |
<source lang="bash"> |
||
gcc -m32 -o output32 hello.c |
gcc -m32 -o output32 hello.c |
||
</source> |
|||
:With <tt>ld</tt>, link using ''emulation'' <tt>elf_i386</tt>: |
|||
<source lang=bash> |
|||
ld -m elf_i386 -o output32 hello.o |
|||
</source> |
</source> |
||
Revision as of 19:50, 1 July 2012
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
- With ld, link using emulation elf_i386:
ld -m elf_i386 -o output32 hello.o
- 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