A cross compiler is a compiler capable of creating executable code for a platform other 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, on which various kinds of microcontrollers run with a minimal amount of memory for their own purpose).
The fundamental use of a cross compiler is to separate the build environment from the target environment. This is useful in a number of situations:
Use of virtual machines (such as Java's JVM) ameliorate some of the problems for which cross compilers were developed. The virtual machine method allows the same compiler output to be used by both the host and the target system.
gcc relies upon the binaries of binutils for the targeted platform to be available. Especially important is 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 operating systems 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 targeted platform on the host platform. At least the crt0, ... components of the library has to be available in some way. You can choose to compile the full C library, but that can be too large for many platforms. The alternative is to use newlib, which is a small C library containing only 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.
This is a technique for building cross compilers for other machines. That is, use machine A to build a cross compiler that runs on machine B to create executables for machine C. When using the Canadian Cross with gcc, there may be four compilers involved.
On Machine A:
Note that you will not be able to execute the resulting compiler on your build machine A. You would use gcc cross compiler from machine B to machine C (4) on machine B to compile an application into executable code that would then be copied to machine C and executed on machine C.
Cross-Compiler | Compilador cruzado | Cross-kompilator | Кросс-компилятор
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Cross compiler".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world