Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine host value for configure when using cross compiler

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?

like image 394
Omer Dagan Avatar asked Feb 24 '14 14:02

Omer Dagan


People also ask

What is host triplet?

Host triples identify the architecture and OS of the system that will ultimately run your executable. Mine is x86_64-pc-linux-gnu for example. The general form is cpu-vendor-os . Windows might be something like x86_64-pc-windows-msvc .

Is GCC a cross compiler?

Explanation: GCC, a free software collection of compilers, also can be used as cross compile. It supports many languages and platforms.


2 Answers

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.

like image 120
vinay hunachyal Avatar answered Sep 20 '22 03:09

vinay hunachyal


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.

like image 44
Drugbird Avatar answered Sep 21 '22 03:09

Drugbird