How to install armv7-unknown-linux-musleabihf

Hello, I would like to install armv7-unknown-linux-musleabihf, I am trying to do it using

sudo apt install armv7-unknown-linux-musleabihf

However getting error

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package armv7-unknown-linux-musleabihf

You can't add rust targets via apt, and you shouldn't try to get rust from there either. Assuming you're cross-compiling, then rustup target add armv7-unknown-linux-musleabihf should do the trick. If you get linker errors then add

[target.armv7-unknown-linux-musleabihf]
linker = "rust-lld"

to your .cargo/config.toml file.

If you aren't cross-compiling and want to install rust for development installing it via the standard method for linux should be fine.

1 Like

That only works for bare metal targets and for windows. Linux requires gcc or clang as wrapper to tell the linker where libc can be found and several other flags that are necessary. Instead you have to use armv7-linux-musleabihf-gcc or however the gcc executable for this target is called as linker.

1 Like

Greetings,
Thank you for your response. This is my config.toml file

[target.armv7-unknown-linux-musleabihf]
linker = "armv7-linux-musleabihf-gcc"
rustflags = "-C target-cpu=cortex-a72"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
rustflags = "-C target-cpu=cortex-a72"

I am still getting the same error

unning: "arm-linux-musleabihf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "src/zlib" "-fvisibility=hidden" "-DZ_SOLO" "-DSTDC" "-D_LARGEFILE64_SOURCE" "-D_POSIX_SOURCE" "-o" "/home/akumar/targetarm/target/armv7-unknown-linux-musleabihf/release/build/libz-sys-4915c883ed374848/out/lib/src/zlib/adler32.o" "-c" "src/zlib/adler32.c"
  running: "arm-linux-musleabihf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "src/zlib" "-fvisibility=hidden" "-DZ_SOLO" "-DSTDC" "-D_LARGEFILE64_SOURCE" "-D_POSIX_SOURCE" "-o" "/home/akumar/targetarm/target/armv7-unknown-linux-musleabihf/release/build/libz-sys-4915c883ed374848/out/lib/src/zlib/compress.o" "-c" "src/zlib/compress.c"

  --- stderr


  error occurred: Failed to find tool. Is `arm-linux-musleabihf-gcc` installed?


error: failed to run custom build command for `bzip2-sys v0.1.11+1.0.8`

Caused by:
  process didn't exit successfully: `/home/akumar/targetarm/target/release/build/bzip2-sys-31fd70081932c73a/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=BZIP2_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7-unknown-linux-musleabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7_unknown_linux_musleabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7-unknown-linux-musleabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7_unknown_linux_musleabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-musleabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7_unknown_linux_musleabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  TARGET = Some("armv7-unknown-linux-musleabihf")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_armv7-unknown-linux-musleabihf = None
  CC_armv7_unknown_linux_musleabihf = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_armv7-unknown-linux-musleabihf = None
  CFLAGS_armv7_unknown_linux_musleabihf = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = None
  running: "arm-linux-musleabihf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/home/akumar/targetarm/target/armv7-unknown-linux-musleabihf/release/build/bzip2-sys-22ccfb816aa14efa/out/lib/bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c"
  running: "arm-linux-musleabihf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/home/akumar/targetarm/target/armv7-unknown-linux-musleabihf/release/build/bzip2-sys-22ccfb816aa14efa/out/lib/bzip2-1.0.8/huffman.o" "-c" "bzip2-1.0.8/huffman.c"

  --- stderr


  error occurred: Failed to find tool. Is `arm-linux-musleabihf-gcc` installed?

You will need to install arm-linux-musleabihf-gcc on your system.

Thank you for your response, can you please guide me how can I install it? I tried doing it with apt but seems like it's not working.

Which distro are you using? Debian only provides the glibc variant in the gcc-arm-linux-gnueabihf package, but not the musl variant. If your distro doesn't provide it, you may be able to build it yourself using GitHub - richfelker/musl-cross-make: Simple makefile-based build for musl cross compiler I think.

Another option would be to use clang, which is a lot easier when cross-compiling, especially for more niche targets. If you go that route, set the linker to "ld.lld" and then build CC=clang cargo build --target arm7-unknown-linux-musleabihf.

I am using UBUNTU 20.04

Looks like ubuntu 20.04 only has glibc too.

Do you have any suggestion as when I am using cargo -v build --release --target armv7-unknown-linux-gnueabihf to build I am getting the following error

     Running `rustc --crate-name http_body --edition=2018 /home/abc/.cargo/registry/src/github.com-1ecc6299db9ec823/http-body-0.3.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=b1e3ccb6a23e7840 -C extra-filename=-b1e3ccb6a23e7840 --out-dir /home/abbc/a/target/armv7-unknown-linux-gnueabihf/release/deps --target armv7-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-gcc -L dependency=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps -L dependency=/home/akumar/targetarm/target/release/deps --extern bytes=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps/libbytes-5318421955a4f8ab.rmeta --extern http=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps/libhttp-bfe6be4f855d175c.rmeta --cap-lints allow`
error: failed to run custom build command for `libudev-sys v0.1.4`

Caused by:
  process didn't exit successfully: `/home/abc/a/target/release/build/libudev-sys-0463db1d4d4cbd4d/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "pkg-config has not been configured to support cross-compilation.\n\nInstall a sysroot for the target platform and configure it via\nPKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\ncross-compiling wrapper for pkg-config and set it via\nPKG_CONFIG environment variable."', /home/akumar/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

Hi, thank you for your help, can you please suggest which distro support musleabihf, I will try to use that also in addition to using clang as a safe option.

All distros support musleabihf.

Hi! Thank you for your response. If that is possible how can I install target.armv7-unknown-linux-musleabihf ? Please visit How to install armv7-unknown-linux-musleabihf - #10 by bjorn3 they have suggested that Ubuntu 20.04 does not support it.

If you're doing it for rust, just use rustup target add armv7-unknown-linux-musleabihf. For clang, it should be installed out of the box. For GCC, you'd probably have to build it yourself.

Anyway, I just opened up a Linux VM, and to get a hello world to build for armv7-unknown-linux-musleabihf with clang and rust installed, I had to do three things:

  1. install the target via rustup
  2. set .cargo/config.toml to
[target.armv7-unknown-linux-musleabihf]
linker = "lld"
  1. Invoke cargo via CC=clang cargo build --target=armv7-unknown-linux-musleabihf

That should be enough to get most crates built. Crates that depend on C or more platform specific apis might require more effort to get to build, but in that case, it should say in their documentation.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.