Cross-compilation

From Free net encyclopedia

Compiling a program takes place by running a compiler on the build platform. The compiled program will run on the host platform. Usually these two are the same; if they are different, the process is called cross-compilation.

Typically the hardware architecture differs, like for example when compiling a program destined for the MIPS architecture on an x86 computer; but cross-compilation is also applicable when only the operating system environment differs, as when compiling a FreeBSD program under Linux; or even just the system library, as when compiling programs with uClibc on a glibc host.

A "Canadian Cross" is a shortcut to describe a three-way cross-compilation : on platform A, compile a compiler to run on platform B that generates executable for platform C. For instance NetBSD provides a POSIX Unix shell script named "build.sh" which will first build its own toolchain with host's compiler which in turn will be used to build the cross-compiler. Finally the latter will be used to build the whole system.

Cross-compilation is typically more involved and prone to errors than with native compilation. Due to this, cross-compiling is normally only utilized if the target is not yet self-hosting (i.e. able to compile programs on its own), unstable, or the build system is simply much faster. For many embedded systems, cross-compilation is simply the only possible way to build programs, as the target hardware does not have the resources or capabilities.

The autotools packages (i.e. autoconf, automake, and libtool) use the notion of a build platform, a host platform, and a target platform. The build platform is where the code is actually compiled. The host platform is where the compiled code will execute. The target platform usually only applies to compilers as it represents what type of object code the package itself will produce (such as cross-compiling a cross-compiler); otherwise the target platform setting is irrelevant.

For example, consider cross-compiling a video game that will run on the Dreamcast. The machine where the game is compiled is the build platform while the Dreamcast is the host platform.

See also

References