What's the difference of "./configure" option "--build", "--host" and "--target"?

83,297

Solution 1

As noted in this blog post and alluded to in the GCC Configure Terms, --target only applies when you are compiling toolchains. When you are doing normal cross-compilation of a library or binary you use

--build=the architecture of the build machine
--host=the architecture that you want the file to run on

However, when you are building toolchains, things can get more complicated. I think that the following is correct (though I can't say I've ever manually compiled a cross-debugger):

Lets say that you have:

  • a powerpc build machine that you are going to do all compilation on
  • several embedded devices, with mips processors, which your code is going to run on
  • an x86 laptop that you are going to use for debugging these devices in the field

You would configure and build your debugging server (eg gdbserver) to run on your embedded device with

./configure --build=powerpc --host=mips

so that you could putty on to your embedded device and run "gdbserver :1234 a.out" to start debugging and listen on port 1234.

You would then build your debugging client (which connects to and controls the gdbserver) with

./configure --build=powerpc --host=i686 --target=mips 

which you would copy to your x86 laptop so that in the field you could run "gdbclient embedded.device:1234" in order to debug your a.out program.

This all applies to compilers too for which you might want to look at the GCC link above or this section about the Canadian cross compile.

Also note that, in practice, you might not see build, host or target specified because, according to this Autoconf manual page, "target defaults to host, host to build, and build to the result of config.guess."

In a word, build the code on --build, run it on --host with --target architecture environment.

Solution 2

Note: Argument --target makes sense only when building compiler (e.g. GCC). When running configure before building GCC:

  • --build: the machine you are building on
  • --host: the machine you are building for
  • --target: the machine that GCC will produce binary for

From the GCC documentation (Host/Target specific installation notes):

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.

Share:
83,297
eonil
Author by

eonil

Favorite words: "Make it work, make it right, make it fast" — by Kent Beck? "...premature optimization is the root of all evil (or at least most of it) in programming." - from The Art of Computer Programming, by Donald Knuth. "Yes, but your program doesn't work. If mine doesn't have to work, I can make it run instantly and take up no memory." — from Code Complete, by Steve Mcconnell. "Flat is better than nested." — from The Zen of Python, by Tim Peters "Making decisions is slow." — from The Ninja build system manual, author unknown. "A little copying is better than a little dependency." - from Go Proverbs, by Rob Pike Preferred tools: macOS, iOS, Ubuntu. Rust, Swift, VIM, Xcode. SQLite, PostgreSQL, Redis. And a few more trivial stuffs. Feel free to fix my grammar. I always appreciate!

Updated on February 10, 2022

Comments

  • eonil
    eonil about 2 years

    The script ./configure accepts 3 options --build, --host and --target. I'm confusing their roles. What's the difference and semantics of them?

  • dhardy
    dhardy over 9 years
    Which apparently means --target is not relevant to any project which is not itself a compiler. So why is it a standard configure option? Confusing.
  • Tim Čas
    Tim Čas about 9 years
    @dhardy: configure isn't exactly a pinnacle of good and clean design; I guess it's just a result of application-specific feature creep.
  • Black
    Black over 8 years
    How to find out what to put for "host" and "target" ?
  • user1735594
    user1735594 over 8 years
    I guess you are talking about building a new compiler, as "--target" is relevant only for compilers. * "host" is where your new compiler should run. * "target" is where the executables produced by your new compiler should run.
  • infoclogged
    infoclogged about 7 years
    doesnt this make this as a wrong answer, because --host=i686 isnt valid here?
  • gfan
    gfan over 5 years
    If I want to get a gcc, for example run "./configure --build=powerpc --host=i686 --target=mips ", Is the output executable crippled? usually, gcc is a powerful tool that can build c code, then output many kind of result for many platform. Here if I use '--target=mips', does the specified gcc lost the ability?
  • supmethods
    supmethods over 5 years
    The answer provided mention the compilation was done for the MIPS target and this is the build, and the host is the debugger for the MIPS machine. Does this mean that the debugger/compiler was also built by the powerpc? This is a comment I got from another user (Ned): build = where am I compiling the compiler, host = where the compiler will run, target = what code will the compiler produce. Reference: stackoverflow.com/questions/7088576/…
  • supmethods
    supmethods over 5 years
    According to Ned, wouldn't this mean the powerpc is both the build/host, x86 machine a target of the debugger, and the target as MIPS system. Can you explain more what "building for" and "building on" is? I referencing to gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html.
  • wirtsi
    wirtsi almost 5 years
    What also might work is to update the config.guess and config.sub files, so the compiler knows more target platforms .. you can get them here: gnu.org/software/gettext/manual/html_node/config_002eguess.h‌​tml
  • MarcH
    MarcH about 4 years
    IMHO the frequent confusion is because these terms are relative: they shift when you use the cross-compiler built by someone else mesonbuild.com/Cross-compilation.html