Cross-compilers - GCC and Cross Compilation

GCC and Cross Compilation

GCC, a free software collection of compilers, can be set up to cross compile. It supports many platforms and languages.

GCC requires that a compiled copy of binutils be available for each targeted platform. 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. GCC can then be run normally provided that the tools, which binutils creates, are available in the path, which can be done using the following (on UNIX-like operating systems with bash):

PATH=/path/to/binutils/bin:${PATH} make

Cross compiling GCC requires that a portion of the target platform's C standard library be available on the host platform. The programmer may choose to compile the full C library, but this choice could be unreliable. The alternative is to use newlib, which is a small C library containing only the most essential components required to compile C source code.

The GNU 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 compiler is actually compiled. In most cases, build should be left undefined (it will default from host). The host platform is where the output artefacts from the compiler will be executed. The target platform is used when cross compiling cross compilers, it represents what type of object code the package itself will produce; otherwise the target platform setting is irrelevant. For example, consider cross-compiling a video game that will run on a Dreamcast. The machine where the game is compiled is the host platform while the Dreamcast is the target platform.

This article's tone or style may not reflect the encyclopedic tone used on Wikipedia. See Wikipedia's guide to writing better articles for suggestions.

Another method that is popularly used by embedded Linux developers is to use GCC compilers with Scratchbox or the newer scratchbox2. These tools create a "chrooted" sandbox where the programmer can build up the necessary tools, libc, and libraries without having to set extra paths. It also has facilities for tricking the runtime into thinking it is on (for example) an ARM CPU so things like configure scripts will run. The downside to Scratchbox is that it is slower and most of your tools that are on the host must be moved into Scratchbox to function.

Read more about this topic:  Cross-compilers

Famous quotes containing the words cross and/or compilation:

    Flood-tide below me! I see you face to face!
    Clouds of the west—sun there half an hour
    high—I see you also face to face.
    Crowds of men and women attired in the usual costumes, how curious you are to me!
    On the ferry-boats the hundreds and hundreds that cross, returning
    home, are more curious to me than you suppose,
    And you that shall cross from shore to shore years hence are more to me, and more in my meditations, than you might suppose.
    Walt Whitman (1819–1892)

    The United States Constitution has proved itself the most marvelously elastic compilation of rules of government ever written.
    Franklin D. Roosevelt (1882–1945)