Cross-compilation for ARM fails because arpa/inet.h is not found

My binary depends on surf, which depends on http-client, which depends on isahc, which depends on curl, which depends on curl-sys, which depends on libnghttp2-sys.

I am trying to cross-compile for the Raspberry PI 4 (ARMv7) as follows:

$ CC_arm_unknown_linux_gnueabihf=arm-none-eabi-gcc cargo build --target arm-unknown-linux-gnueabihf

I run ArchLinux and arm-none-eabi-gcc was installed from the arm-none-eabi-gcc package. I also installed the arm-none-eabi-newlib package, which includes the standard library for ARM devices.

The build fails with the following error, while trying to build the libnghttp2-sys crate:

The following warnings were emitted during compilation:

warning: In file included from nghttp2/lib/nghttp2_frame.c:33:
warning: nghttp2/lib/nghttp2_net.h:33:12: fatal error: arpa/inet.h: No such file or directory
warning:    33 | #  include <arpa/inet.h>
warning:       |            ^~~~~~~~~~~~~
warning: compilation terminated.

error: failed to run custom build command for `libnghttp2-sys v0.1.4+1.41.0`

Caused by:
  process didn't exit successfully: `/home/dev/myprogram/target/debug/build/libnghttp2-sys-58cfd88958948e51/build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("arm-unknown-linux-gnueabihf")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_arm-unknown-linux-gnueabihf = None
  CC_arm_unknown_linux_gnueabihf = Some("arm-none-eabi-gcc")
  CFLAGS_arm-unknown-linux-gnueabihf = None
  CFLAGS_arm_unknown_linux_gnueabihf = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-I" "nghttp2/lib/includes" "-I" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/include" "-DNGHTTP2_STATICLIB" "-DHAVE_NETINET_IN" "-DHAVE_ARPA_INET_H" "-o" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/lib/nghttp2/lib/nghttp2_buf.o" "-c" "nghttp2/lib/nghttp2_buf.c"
  exit code: 0
  running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-I" "nghttp2/lib/includes" "-I" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/include" "-DNGHTTP2_STATICLIB" "-DHAVE_NETINET_IN" "-DHAVE_ARPA_INET_H" "-o" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/lib/nghttp2/lib/nghttp2_callbacks.o" "-c" "nghttp2/lib/nghttp2_callbacks.c"
  exit code: 0
  running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-I" "nghttp2/lib/includes" "-I" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/include" "-DNGHTTP2_STATICLIB" "-DHAVE_NETINET_IN" "-DHAVE_ARPA_INET_H" "-o" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/lib/nghttp2/lib/nghttp2_debug.o" "-c" "nghttp2/lib/nghttp2_debug.c"
  exit code: 0
  running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-I" "nghttp2/lib/includes" "-I" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/include" "-DNGHTTP2_STATICLIB" "-DHAVE_NETINET_IN" "-DHAVE_ARPA_INET_H" "-o" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/lib/nghttp2/lib/nghttp2_frame.o" "-c" "nghttp2/lib/nghttp2_frame.c"
  cargo:warning=In file included from nghttp2/lib/nghttp2_frame.c:33:
  cargo:warning=nghttp2/lib/nghttp2_net.h:33:12: fatal error: arpa/inet.h: No such file or directory
  cargo:warning=   33 | #  include <arpa/inet.h>
  cargo:warning=      |            ^~~~~~~~~~~~~
  cargo:warning=compilation terminated.
  exit code: 1

  --- stderr


  error occurred: Command "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-I" "nghttp2/lib/includes" "-I" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/include" "-DNGHTTP2_STATICLIB" "-DHAVE_NETINET_IN" "-DHAVE_ARPA_INET_H" "-o" "/home/dev/myprogram/target/arm-unknown-linux-gnueabihf/debug/build/libnghttp2-sys-0f6764a7378d445e/out/i/lib/nghttp2/lib/nghttp2_frame.o" "-c" "nghttp2/lib/nghttp2_frame.c" with args "arm-none-eabi-gcc" did not execute successfully (status code exit code: 1).


warning: build failed, waiting for other jobs to finish...
error: build failed

So it seems that arpa/inet.h is missing from the toolchain, but it should be included in the newlib package. Where should I find that header file? It's not even present in my /usr/lib.

You're going to need a arm-linux-gnueabihf glibc toolchain for this to work. Newlib is very minimal and doesn't have UNIX headers like this, and also isn't compatible with Rust's arm-unknown-linux-gnueabihf target (it's meant for bare metal programming, not a system with a linux kernel and networking).

1 Like

I installed that one too, but it didn't solve the issue. I also tried the same thing on Ubuntu, and it fails with the same error. Maybe it's the libnghttp2-sys crate that does not support cross-compilation?

I ended up compiling it directly on a Raspberry Pi, which works but it's kind of annoying.

It's possible. Not all crates handle cross-compilation well. What error do you get? Maybe you need to tell it to use a different compiler, somehow, e.g. arm-linux-gnueabihf-gcc not arm-none-eabi-gcc.

I just checked and a arm-linux-gnueabihf toolchain does have the header. In Ubuntu it's installed to:

/usr/arm-linux-gnueabihf/include/arpa/inet.h