Q:

Cross-compiling coreutils

I have problems trying to cross-compile the GNU coreutils (git clone https://git.savannah.gnu.org/git/coreutils.git) for ARM.
Following other Q&As in the StackExchange network, I ended up with the following procedure:
Setup:
git clone https://git.savannah.gnu.org/git/coreutils.git
cd coreutils/ && ./bootstrap
[...]

Cross-compilation:
export CC=/path/to/toolchain/arm-linux-gnueabihf-gcc
export CXX=/path/to/toolchain/arm-linux-gnueabihf-g++

Compile:
./configure --host=arm-linux-gnueabihf
[...]
make
  GEN      .version
[...]
  GEN      lib/wchar.h
  GEN      lib/wctype.h
  GEN      src/coreutils.h
  GEN      src/dircolors.h
make src/make-prime-list
make[1]: Entering directory '/media/data/sources/coreutils'
  CC       src/make-prime-list.o
  CCLD     src/make-prime-list
make[1]: Leaving directory '/media/data/sources/coreutils'
  GEN      src/primes.h
/bin/bash: src/make-prime-list: cannot execute binary file: Exec format error
Makefile:14603: recipe for target 'src/primes.h' failed
make: *** [src/primes.h] Error 126

Y U no compile?
I see that it tries to run this make-prime-list on my x64 machine, hence the format error. But it is supposed to compile with the toolchain anyway...
Any suggestion?

A:

To cross-compile, you should only specify the --host option to ./configure, you mustn’t specify your cross-compiler as CC and CXX. The configure script should do the right thing, using the host compiler for host binaries such as make-prime-list, and the cross-compiler for target binaries...
However it appears that it doesn’t, so src/primes.h can’t be generated. That file doesn’t appear to be arch-specific though, and make clean doesn’t remove it, so the following works for me:
./configure && make

to build make-prime-list for the build architecture, and use that to generate src/primes.h, followed by
make clean && ./configure --host=arm-linux-gnueabihf && make

to cross-compile the target binaries.

