Search
Desktop

What is a cross-compiler?

Published 1 min readBy Programming4us Editorial Team
1.2 WHAT IS A CROSS-COMPILER?
A cross-compiler is a compiler that runs on one machine and produces object code for another machine. The cross-compiler is used to implement the compiler, which is characterized by three languages:
  1. The source language,

  2. The object language, and

  3. The language in which it is written.

If a compiler has been implemented in its own language, then this arrangement is called a "bootstrap" arrangement. The implementation of a compiler in its own language can be done as follows.

Implementing a Bootstrap Compiler

Suppose we have a new language, L, that we want to make available on machines A and B. As a first step, we can write a small compiler: SCAA, which will translate an S subset of L to the object code for machine A, written in a language available on A. We then write a compiler SCSA, which is compiled in language L and generates object code written in an S subset of L for machine A. But this will not be able to execute unless and until it is translated by SCAA; therefore, SCSA is an input into SCAA, as shown below, producing a compiler for L that will run on machine A and self-generate code for machine A: SCAA.

Now, if we want to produce another compiler to run on and produce code for machine B, the compiler can be written, itself, in L and made available on machine B by using the following steps: