Cross compiler
|
A cross compiler is a compiler capable of creating executable code for another platform than the one on which the cross compiler is run. Such a tool is handy when you want to compile code for a platform that you don't have access to, or because it is inconvenient or impossible to compile on that platform (as is the case with embedded systems.)
Compiling a gcc cross compiler
gcc is a free cross compiler that supports dozens of platforms and a handful of languages. However, due to limited volunteer time and the huge amount of work it takes to maintain working cross compilers, in many releases some of the cross compilers are broken.
gcc relies upon the binaries of binutils for the targeted platform to be available. Especially important is as - the GNU Assembler. Therefore, binutils first has to be compiled correctly with the switch --target=some-target
sent to the configure script. gcc also has to be configured with the same --target
option. Then gcc can be compiled as normal provided that the tools binutils creates are available in the path. On unix-like OS:es with bash, that can be accomplished with the following:
PATH=/path/to/binutils/bin:$PATH make
Cross compiling gcc requires that a portion of the C standard library is available for the targetted platform on the host platform. Atleast the crt0, ... components of the library has to be available in some way. You can either choose to compile the full C library but it can be too large for many platforms. The alternative is then to use newlib, which is a small C library containing just the most essential components required to get C source code compiled. To configure gcc with newlib use the switch --with-newlib
to the configure script.