5

I'm seeing a lot of conflict information and would like some clarification. build, host and target

There are three system names that the build knows about: the machine you are building on (build), the machine that you are building for (host), and the machine that GCC will produce code for (target). When you configure GCC, you specify these with --build=, --host=, and --target=.

Actually, I don't understand what the difference between host and target in the above definition.

Some other page says

‘host’ is the machine (or architecture, or platform) that you are using to compile the code; ‘target’ is the machine (or architecture, or platform) that is intended to run the code.

This makes sense to me, but in this explanation, is the host always the same as the build ?? I'm pretty confused.

In my case, I am configuring such that the compiler (GCC) runs on x86_64 machine and the binary executable runs on ARM. The program is written in C, so the compiler is GCC.

   ./configure --build=x86_64 --host=x86_64 --target=arm-linux-gnueabihf
    make
    make install

It sounds like build, host are both x86_64 and target is arm. Is that correct?

I am compiling my own embedded program that runs on Jenkins machine (x86_64). And the embedded program runs on ARM based machine.

leopoodle
  • 2,110
  • 7
  • 24
  • 36
  • What exact program are you compiling? Some cross-compiler version of [GCC](http://gcc.gnu.org/), or simply your own program with an already available `gcc` binary? Show some [MCVE] (so show some source in your question) and show the *exact* compilation commands you are using (and explain on what computers they are running). Tell about your systems (what is the host, the build machine, the target one). Please **edit your question** to improve it a lot. It currently is confusing. – Basile Starynkevitch Oct 30 '17 at 09:15
  • Even with the edit your question is unclear: What does "I am configuring such that the compiler" means? *What is configured, and how??* Please **improve your question** even more. *Give the exact commands* involved. Explain on which computers they are running. **What compiler do you use?** *and* **How do you use it??** – Basile Starynkevitch Oct 30 '17 at 09:38
  • Obviously English is not your mother language (and neither is it for me; I am French). So improve your wording (perhaps with the help of some dictionnary), and give the *exact commands* you are using. IMHO the sentence "I am configuring such that the compiler runs on x86_64 machine and the binary executable runs on ARM" does not make any sense (you don't tell what and how your are configuring). Given that English is not easy for you, you need to add more information and redundancy in your question. – Basile Starynkevitch Oct 30 '17 at 09:41
  • Take time to **improve your question** by giving some [MCVE] and by giving the **exact commands** used to build and to test your program. – Basile Starynkevitch Oct 30 '17 at 09:46
  • @BasileStarynkevitch it's ok. I think you clarified my misunderstanding. Thanks a lot. – leopoodle Oct 30 '17 at 09:47
  • But please improve your question as a courtesy to us and to future readers. We deserve your efforts. – Basile Starynkevitch Oct 30 '17 at 09:47
  • I still don't understand what *exact* compiler you are using (GCC has lots of variants and configurations!) and what actual program you try to compile and to test (on what machine; the OS also matters). – Basile Starynkevitch Oct 30 '17 at 09:49
  • BTW, **GCC should *not* be built in its *source* tree** (and that is [documented](https://gcc.gnu.org/install/configure.html) explicitly) and you'll better pass some `--program-suffix=-steve` to its `../gcc-7.2/configure` script – Basile Starynkevitch Oct 30 '17 at 09:50

2 Answers2

4

Lets say I have a PowerPC machine making a compiler that you will use (run) on an x86 machine that will make binaries that run on an ARM.

That makes the PPC the build, the x86 the host, and the target is the ARM. As Basile commented, this is a Canadian-cross.

It's less common to have a build and host that are different, but it certainly does happen. Sometimes the build and host are even the same architecture, but there's something different about the environments that cause this. Making a custom toolchain on my x86 will mean that build and host are x86, but the host may have different libraries, or versions of dependencies, than the build. This is the case when building sand-boxed toolchains for embedded development that run on a build server, for example.

Joe
  • 7,378
  • 4
  • 37
  • 54
  • 1
    And that situation is called a Canadian-cross compiler. I don't know why. – Basile Starynkevitch Oct 30 '17 at 08:08
  • @BasileStarynkevitch I'm even more confused. I am not making a compiler. I am use Makefile to generate a binary that runs on ARM. The makefile runs on x86_64 machine, but the binary executable needs to run on ARM machine. – leopoodle Oct 30 '17 at 09:11
  • @SteveHe: You are configuring GCC, so you *are* building a compiler (some binary of `gcc`). Otherwise, your question does not makes any sense. – Basile Starynkevitch Oct 30 '17 at 09:13
  • @BasileStarynkevitch I see. So, in my case, it sounds like build, host are both x86_64 and target is arm. Does it sound right to you? – leopoodle Oct 30 '17 at 09:32
  • @SteveHe: don't comment here, but **edit your question** to improve it a lot. I just voted to close it, because it is very unclear. – Basile Starynkevitch Oct 30 '17 at 09:33
1

"There are three system names that the build knows about: the machine you are building on (build), the machine that you are building for (host), and the machine that GCC will produce code for (target). When you configure GCC, you specify these with --build=, --host=, and --target="

...

  • If build, host, and target are all the same, this is called a native.
  • If build and host are the same but target is different, this is called a cross.
  • If build, host, and target are all different this is called a canadian (for obscure reasons dealing with Canada’s political party and the background of the person working on the build at that time).
  • If host and target are the same, but build is different, you are using a cross-compiler to build a native for a different system.
    • Some people call this a host-x-host, crossed native, or cross-built native.
  • If build and target are the same, but host is different, you are using a cross compiler to build a cross compiler that produces code for the machine you’re building on.
    • This is rare, so there is no common way of describing it. There is a proposal to call this a crossback.

Source: https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html

Someone already gave an example of the 'Canadian'.

An example of a cross-compilation is that when building sox from source (the Linux sound library) you need to provide 32-bit binaries for the codecs etc. I just came across this situation on a 64-bit machine, and I want to build it for my own use, which means in this case:

  • The build is the host (my machine)
  • The target is a 32-bit system

This is my understanding anyway, I agree this can be a bit confusingly explained, hope this helps :-)

Louis Maddox
  • 5,226
  • 5
  • 36
  • 66
  • > the machine that you are building for (host), and the machine that GCC will produce code for (target). – leopoodle Mar 27 '21 at 08:08
  • I don't understand the difference between `host` and `target` in the explanations above. The machine we build for should be the same as the machine GCC produces the code for, no? – leopoodle Mar 27 '21 at 08:09
  • No. In my `sox` example, the machine built for (my 64 bit machine) was running 32 bit libraries. My machine could run those libraries even though it didn’t match its architecture (my distro achieves this with [MultiarchSpec](https://wiki.ubuntu.com/MultiarchSpec), and [previously](http://askubuntu.com/questions/107230/what-happened-to-the-ia32-libs-package) via `ia32-libs`). That question was also asked [here](https://stackoverflow.com/q/7088576/2668831) and answered as “build = where am I compiling the compiler, host = where the compiler will run, target = what code will the compiler produce” – Louis Maddox Mar 31 '21 at 08:08