cross-compilation terminologies --- build, host and target
Asked Answered
M

3

11

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.

Monanthous answered 30/10, 2017 at 8:0 Comment(8)
What exact program are you compiling? Some cross-compiler version of GCC, or simply your own program with an already available gcc binary? Show some minimal reproducible example (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.Early
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??Early
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.Early
Take time to improve your question by giving some minimal reproducible example and by giving the exact commands used to build and to test your program.Early
@BasileStarynkevitch it's ok. I think you clarified my misunderstanding. Thanks a lot.Monanthous
But please improve your question as a courtesy to us and to future readers. We deserve your efforts.Early
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).Early
BTW, GCC should not be built in its source tree (and that is documented explicitly) and you'll better pass some --program-suffix=-steve to its ../gcc-7.2/configure scriptEarly
B
8

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.

Babul answered 30/10, 2017 at 8:6 Comment(5)
And that situation is called a Canadian-cross compiler. I don't know why.Early
@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.Monanthous
@SteveHe: You are configuring GCC, so you are building a compiler (some binary of gcc). Otherwise, your question does not makes any sense.Early
@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?Monanthous
@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.Early
I
4

"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 :-)

Intine answered 12/2, 2021 at 19:53 Comment(3)
> the machine that you are building for (host), and the machine that GCC will produce code for (target).Monanthous
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?Monanthous
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, and previously via ia32-libs). That question was also asked here and answered as “build = where am I compiling the compiler, host = where the compiler will run, target = what code will the compiler produce”Intine
S
1

The OP is likely referring to the --build, --host, and --target options in the GCC's configure script (and also the configure script of Binutils and related tools).

These 3 terms are well defined in the GNU build system (Autotools), and yet different developers and users might use the terms host and target in a loose manner, that can cause confusion to readers.

I think the Toolchain Notes page in the Linux From Scratch book has a good explanation for the 3 terms:

The build

is the machine where we build programs.

The host

is the machine/system where the built programs will run.

The target

is only used for compilers. It is the machine the compiler produces code for. It may be different from both the build and the host.

The three machine type specifications are needed for configuring and building a package. For most configurations, either the --build and --host would be the same, or --host and --target be the same.

If the package to be built is not a compiler, then --target is not applicable and only --build and --host are valid options when configuring.

One best way to learn how to specify these three options is try building a cross toolchain by yourself, through a book like Linux From Scratch (but avoid highly automated tool builders like crosstool-NG), because sometimes you need to assign a what you called "target" machine to --host for some packages, and to --target to other packages.

Specifically:

  1. When you are building a cross-assembler (Binutils) and cross-compiler (GCC) to an ARM machine, and your build machine is a x86-64 Linux system, then you need to specify --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf. Here, the cross-compiler would actually be run on your x86-64 machine, not on your (perhaps embedded) ARM system.
  2. When you are building a C library (because GCC package doesn't ship with a C library; Glibc is usually configured and built separately), you need the library to run on the ARM machine and not on x86-64, so --build=x86_64-linux-gnu --host=arm-linux-gnueabihf. Note that --target is not applicable here, and for this configuration a cross compiler would be invoked. A cross compiler can be identified with the machine name as the prefix (for example, "arm-linux-gnueabihf-gcc") and it can be the cross compiler you just built in point (1.).
  3. For building other packages that would run on your ARM system, specify --build=x86_64-linux-gnu --host=arm-linux-gnueabihf like the C library case in point (2.).
  4. If you want to build a native compiler for your ARM system (which is unlikely, as we assume this ARM machine is slow at compiling things), specify --build=x86_64-linux-gnu --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf. This configuration does not produce a cross compiler, but uses a cross compiler to build a native compiler, hence it is nicknamed "crossed native".
  5. I don't think the OP needs to learn about the Canadian cross compiling at the moment (where --build, --host, and --target machines are all different). The Canadian cross configuration is vaild for a build system, but the use case is more uncommon.
Satyriasis answered 28/4 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.