Cross compiling in Linux
Introduction
To cross compile means to generate object code that is meant to be run on an architecture other than the one you were using to build that object code. Some well known cross complilation scenarios are:- Building/compiling Windows 32-bit applications under Linux
- Building Linux binaries for other processors
Figuring out the architecture
UNIX uses three identifiers for each architecture. These are concatenated on a single string. These are:- Processor type
- Machine/vendor
- Operating System
- i386-unknown-linux-gnu
- mipsel-unknown-linux-gnu
- i386-unknown-cygwin32
- ppc64-unknown-linux-gnu
Where to install
Most people like to install the cross compiling utilities in some separate place, like /usr/cross-tools/. I personally like them to reside side-by-side with my current environment. If you like to use my settings change the prefixes in the examples from /usr/cross-tools/ to /usr. I decline any responsability for any damage you might get to your system if you use the /usr prefix. You have been warned!.Necessary tools
The following examples are for MIPS, but you can use other architectures. The most basic tools you will need are:- Binutils (assembler and companions) that will run on i386 and generate object code for MIPS
- GCC (C compiler that will run on i386 and generate assembly for MIPS
Building binutils
You can fetch binutils from The GNU site. Extract the software to your favorite location.
Enter the directory and configure the package:./configure --target=mipsel-unknown-linux-gnu --prefix=/usr/cross-toolsThen if everything goes OK, just type:
make
This will build the necessary tools.
The only thing you need to do is install the package. To do so just do:
make install
It will install binutils under the prefix you specified.
You can then check if you have the tools there.