21

General question: If I use a cross compiler, how can I tell the value of the "--host" option I should give when I run configure?

Specific: I'm using cross compiler for arm64 arch. What is the correct "--host" value to use?

Brian
  • 14,610
  • 7
  • 35
  • 43
Omer Dagan
  • 14,868
  • 16
  • 44
  • 60
  • Though you asked for the `host` value, I think you *really* wanted the `build` value. `host` is the machine configure is running on, and you get that with `config.guess`. You want the triplet for `build`, and that is the machine the package will eventually run on. (Don't use `--target`; that is used for cross-compiling toolchains). The triplets are shared for both, but there is no easy way to get a list of the triplets. Also see [How To Configure for Android?](https://lists.gnu.org/archive/html/autoconf/2015-01/msg00021.html) on the Autoconf mailing list. – jww Oct 08 '18 at 12:41

3 Answers3

50

If I use a cross compiler, how can I tell the value of the --host option I should give when I run ./configure?

Three machines must be distinguished when discussing toolchain creation

  • The build machine, where the toolchain is built.
  • The host machine, where the toolchain will be executed.
  • The target machine, where the binaries created by the toolchain are executed.

Four common build types are possible for toolchains are:

  • Native build i.e. BUILD==HOST==TARGET
    Used to build normal gcc for workstation. e.g. BUILD==HOST==TARGET==x86

  • Cross-build i.e. BUILD==HOST!=TARGET
    Used to build toolchain that works on your workstation but generates binary for target. e.g. BUILD==HOST==x86 TARGET==arm

  • Cross-native build i.e. BUILD!=HOST==TARGET
    Used to toolchain that works on your target and generates binary for target. e.g BUILD==x86 HOST==TARGET==ARM

  • Canadian toolchain i.e. BUILD!=HOST!=TARGET
    Used to build ARCHITECTURE A a toolchain runs on B and generates binary for architecture C. e.g.BUILD==x86 HOST==mac TARGET==arm

With armed this basics coming to your question.

For any software, first run ./configure --help

Host type:

--build=BUILD           configure for building on BUILD [BUILD=HOST]
--host=HOST             configure for HOST [guessed]
--target=TARGET         configure for TARGET [TARGET=HOST]

You will find above so depending on what you want to do, you need to set it for cross compiling. If all options are available, then you want to execute on arm target then set --host={your toolchain triplet} --target={your toolchain triplet}.

For example, if you are using arm-none-linux-gnueabi-gcc, set --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi. This will write to your makefile. Finally, generated executable will run on target. For --build this will be automatically set, no need to worry.

For some software package only two option available i.e host and build. here if set host is enough to cross-compile

Specific: I'm using cross compiler for arm64 arch. What is the correct --host value to use?

For x86_64, --host={triplet} is generally given, so I think the same should work for arm64 by setting --host={triplet} for your toolchain, but I'm not sure.

pevik
  • 4,523
  • 3
  • 33
  • 44
vinay hunachyal
  • 3,781
  • 2
  • 20
  • 31
  • 1
    This is a buried gem. Thanks for a well-written answer! – hesham_EE Mar 07 '15 at 01:44
  • 2
    Did anyone figure out what the "--host" value should be for arm64? – PixelPerfect3 Aug 25 '15 at 22:59
  • @PixelPerfect3 it should be aarch64-linux – Zain Ali Aug 31 '17 at 07:13
  • 2
    Sorry to bring that again, but @PixelPerfect3 is right - the question was how to figure out the right values for --host and --target options of the configure. Are there any tools to call, to get the right value? Or any config files to check for these values? Independently of the platform and configurations - generic approach on how to collect these values. Taking parts of "triplets" from tool chain name/prefix is not a generic option. It is more guessing and hoping. – OpalApps Oct 11 '17 at 11:55
  • Where to find the list of standard architectures for auto tools? I tried to build for arm64 and X86_64 but they end up having the same architecture when I set host to arm64 and x86_64-apple-darwin. – kakyo Oct 09 '19 at 07:48
  • It's very common that autoconf projects will cross compile correctly just with `--host` switch set and correct cross toolchains are used, without the `--target` switch. Is it correct to assume that target will be same as `--host` when only the latter is present? – ceztko Feb 21 '20 at 09:56
16

The easiest way to find out what to input in --host, is by running config.guess on the host machine. On my machine it was located in /usr/share/automake-1.15/ , but I recommend running locate config.guess to find it.

The script is open source (GPL) and available at this address in case it is not available on your machine:

https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess

On my target machine, a tegra X1 (also an aarch64) the answer it gave was aarch64-unknown-linux-gnu, which seems to work fine for cross-compiling.

Florian Castellane
  • 1,197
  • 2
  • 14
  • 38
Drugbird
  • 168
  • 1
  • 6
  • 2
    This has to be a correct/accepted answer! Thanks @Drugbird! config.guess delivers at least the host name correctly. Would also be nice to have a correct way to get the target name too. A list of some kind, or reference the hardware vendor refers to. It is difficult to believe that there is nothing like that available. – OpalApps Oct 11 '17 at 12:17
5

--host is the "triplet" for the machine on which your resultant build will ultimately run. In your case "arm64" is the architecture, but it is only one piece of the triplet. In any event it maps to the string "aarch64" in the triplet. One possible value is

--host=aarch64-linux-android

this page from gnu.org gives the definitive answer about --host/--target/--build usage

sorenoid
  • 669
  • 7
  • 6