Reputation: 2482
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.
Upvotes: 11
Views: 9856
Reputation: 724
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:
--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.--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.).--build=x86_64-linux-gnu --host=arm-linux-gnueabihf
like the C library case in point (2.).--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".--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.Upvotes: 1
Reputation: 5576
"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
, andtarget
are all the same, this is called a native.- If
build
andhost
are the same buttarget
is different, this is called a cross.- If
build
,host
, andtarget
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
andtarget
are the same, butbuild
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
andtarget
are the same, buthost
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:
build
is the host
(my machine)target
is a 32-bit systemThis is my understanding anyway, I agree this can be a bit confusingly explained, hope this helps :-)
Upvotes: 4
Reputation: 7818
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.
Upvotes: 8