Adding these 2 environments worked for me:

export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
export CC=aarch64-linux-gnu-gcc
Answer from lu ji on Stack Overflow
🌐
Jensd's I/O buffer
jensd.be › 1126 › linux › cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
Cross compiling for arm or aarch64 on Debian or Ubuntu | Jensd's I/O buffer
January 26, 2021 - After downloading and extracting the source code, we need to run the configure-script for libpcap first. Only this time, we need to set our compiler to the musl-compiler for our cross compilation by setting CC to: aarch64-linux-musl-gcc:
Discussions

windows subsystem for linux - How to get aarch64 version of musl on Debian for qemu user mode - Unix & Linux Stack Exchange
I have qemu user mode and I try running it with qemu-aarch64 -L /usr/aarch64-linux-gnu/ binary_name but I get the error · /lib/ld-musl-aarch64.so.1: No such file or directory ... sudo apt-get install install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static libc6-dev-arm64-cross ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Can't compile ring with target aarch64-unknown-linux-musl
I don't use ring directly but via jsowebtoken, rustls, etc. I am trying to compile on AWS Graviton EC2 and get the following error for the following command: cargo build --release --target aarc... More on github.com
🌐 github.com
23
October 13, 2021
Cross compilation, Linux, x86_64 host, aarch64 target
I am trying to CC=aarch64-linux-musl-gcc cargo install atuin --target aarch64-unknown-linux-musl Rust 1.75 was installed with curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target aarch64-unknown-linux-musl and my PATH is set. My cross compiler is built with GitHub ... More on users.rust-lang.org
🌐 users.rust-lang.org
10
0
January 22, 2024
Crosscompile aarch64-unknown-linux-GNU to aarch64-unknown-linux-MUSL?
It looks like bindgen is trying to generate bindings for the native target, not cross compile target. You can read their documentation on environment variables that control this. More on reddit.com
🌐 r/rust
2
3
November 4, 2024
🌐
GitHub
github.com › rust-lang › rust › issues › 46651
Cannot cross-compile aarch64-musl on x86_64 linux · Issue #46651 · rust-lang/rust
December 11, 2017 - I installed musl the same way for both aarch64 and for armhf, so I'm not sure what the issue would be. Furthermore, I can compile a simple hello-world application written in C with the musl standard library just fine. Note: I have encountered this issue both in Arch Linux with the 4.14.4 kernel and Ubuntu 16.04 with the 4.4.0 kernel.
Author   asonix
🌐
Stack Exchange
unix.stackexchange.com › questions › 619233 › how-to-get-aarch64-version-of-musl-on-debian-for-qemu-user-mode
windows subsystem for linux - How to get aarch64 version of musl on Debian for qemu user mode - Unix & Linux Stack Exchange
I have qemu user mode and I try running it with qemu-aarch64 -L /usr/aarch64-linux-gnu/ binary_name but I get the error · /lib/ld-musl-aarch64.so.1: No such file or directory ... sudo apt-get install install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static libc6-dev-arm64-cross gcc-aarch64-linux-gnu
🌐
Arch Linux
aur.archlinux.org › packages › aarch64-linux-musl
AUR (en) - aarch64-linux-musl
Skipped :: (1/1) Parsing SRCINFO: ... aarch64-linux-musl :: Import? [Y/n] Y :: Importing keys with gpg... gpg: WARNING: server 'dirmngr' is older than us (2.2.40 < 2.4.5) gpg: Note: Outdated servers may lack important security fixes. gpg: Note: Use the command "gpgconf --kill all" to restart them. gpg: key 56BCDB593020450F: no user ID gpg: Total number processed: 1 -> problem importing keys · aarch64-linux-gnu-gcc is a runtime ...
🌐
GitHub
github.com › briansmith › ring › issues › 1414
Can't compile ring with target aarch64-unknown-linux-musl · Issue #1414 · briansmith/ring
October 13, 2021 - Caused by: process didn't exit successfully: /tmp/lambda_build/target/release/build/ring-6fdf78c41c5d5ad7/build-script-build (exit status: 101) --- stdout OPT_LEVEL = Some("z") TARGET = Some("aarch64-unknown-linux-musl") HOST = Some("aarch64-unknown-linux-gnu") CC_aarch64-unknown-linux-musl = None CC_aarch64_unknown_linux_musl = None TARGET_CC = None CC = None CROSS_COMPILE = None CFLAGS_aarch64-unknown-linux-musl = None CFLAGS_aarch64_unknown_linux_musl = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") CARGO_CFG_TARGET_FEATURE = None
Author   ghost
🌐
musl libc
wiki.musl-libc.org › getting-started.html
Using the musl-gcc wrapper
Whether building your own or downloading binaries, you need to select the appropriate GCC-style tuple for the architecture/ABI you want to target. It takes the form [arch]-linux-musl[abi_modifiers]. For example, ARM is arm-linux-musleabi for standard soft-float EABI and arm-linux-musleabihf ...
Find elsewhere
🌐
Reddit
reddit.com › r/rust › crosscompile aarch64-unknown-linux-gnu to aarch64-unknown-linux-musl?
r/rust on Reddit: Crosscompile aarch64-unknown-linux-GNU to aarch64-unknown-linux-MUSL?
November 4, 2024 -

I did read that for cross-compiling from Windows to Linux, you need to supply the rust-lld linker in the Cargo config; but (un?)fortunately my situation does not seem to be that simple.

On Ubuntu, I installed musl and musl-dev. This means that I have aarch64-linux-musl-gcc in my $PATH and should have the required libraries. However, when I try to cargo build --target aarch64-unknown-linux-musl, I see this:

error: failed to run custom build command for `rquickjs-sys v0.6.2`

Caused by:
  process didn't exit successfully: `/opt/surrealdb/target/debug/build/rquickjs-sys-f5cc455b87df8099/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=CARGO_FEATURE_BINDGEN
  cargo:rerun-if-env-changed=CARGO_FEATURE_UPDATE_BINDINGS
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_BYTECODE
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_GC
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_GC_FREE
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_FREE
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_LEAKS
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_MEM
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_OBJECTS
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_ATOMS
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_SHAPES
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_MODULE_RESOLVE
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_PROMISE
  cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_READ_OBJECT
  Applying patch patches/error_column_number.patch
  can't find file to patch at input line 5
  Perhaps you used the wrong -p or --strip option?
  The text leading up to this was:
  --------------------------
  |diff --git a/Makefile b/Makefile
  |index 0270a6a..1c78547 100644
  |--- a/Makefile
  |+++ b/Makefile
  --------------------------
  No file to patch.  Skipping patch.
  1 out of 1 hunk ignored
  patching file cutils.c
  patching file cutils.h
  patching file quickjs-atom.h
  patching file quickjs-opcode.h
  patching file quickjs.c
  patching file quickjs.h
  patching file tests/test_line_column.js
  Applying patch patches/get_function_proto.patch
  patching file quickjs.c
  Hunk #1 succeeded at 2222 (offset 7 lines).
  patching file quickjs.h
  Applying patch patches/check_stack_overflow.patch
  patching file quickjs.c
  Hunk #1 succeeded at 1622 (offset 32 lines).
  Applying patch patches/infinity_handling.patch
  patching file quickjs.c
  Hunk #1 succeeded at 10391 (offset 105 lines).
  Hunk #2 succeeded at 43407 (offset 317 lines).
  Hunk #3 succeeded at 49735 (offset 317 lines).
  Bindings for target: aarch64-unknown-linux-gnu

  --- stderr
  Ubuntu clang version 18.1.3 (1ubuntu1)
  Target: aarch64-unknown-linux-gnu
  Thread model: posix
  InstalledDir:
  Found candidate GCC installation: /../lib/gcc/aarch64-linux-gnu/11
  Found candidate GCC installation: /../lib/gcc/aarch64-linux-gnu/13
  Selected GCC installation: /../lib/gcc/aarch64-linux-gnu/13
  Candidate multilib: .;@m64
  Selected multilib: .;@m64
  ignoring nonexistent directory "/usr/include/clang/18.1.3/include/"
  ignoring nonexistent directory "/../lib/gcc/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include"
  ignoring nonexistent directory "/include"
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/local/include
   /usr/include/aarch64-linux-gnu
   /usr/include
  End of search list.
  /usr/include/stdio.h:34:10: fatal error: 'stddef.h' file not found
  thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rquickjs-sys-0.6.2/build.rs:351:39:
  Unable to generate bindings: ClangDiagnostic("/usr/include/stdio.h:34:10: fatal error: 'stddef.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

A few things stand out to me:

  • It's using Clang instead of the totally available GCC. Do I need to manually specify cc?

  • stddef.h is most definitively included in musl. But, just to make sure, I went to verify:

# dpkg -L musl-dev | grep -i stddef
/usr/include/aarch64-linux-musl/stddef.h

Sure enough. Technically, everything should be present. I made sure the target is also installed:

# rustup target list --installed
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl

So... what exactly am I missing here?

Thanks and kind regards!

🌐
musl libc
wiki.musl-libc.org › porting › aarch64.html
musl libc - Porting/AArch64
Use Rich Felker’s musl-cross-make and just set ARCH to aarch64 to build the stage1 toolchain for testing (build errors will happen as soon as stage1 gcc is compiled and kernel headers are installed, that is expected.)
🌐
Ubuntu Packages
ubuntu.pkgs.org › 20.04 › ubuntu-universe-arm64 › musl_1.1.24-1_arm64.deb.html
musl_1.1.24-1_arm64.deb Ubuntu 20.04 LTS Download
* New supported architecture: m68k * Bump Standards-Version to 4.2.1. * Drop patch for working around binutils static linking bug. binutils fix is included in 2.31.1-2 (with a follow up in 2.31.1-3). * Drop patch with musl-gcc workaround for linking with default-pie toolchains, as the upstream specs file now includes a better solution.
🌐
GitHub
github.com › axodotdev › cargo-dist › issues › 1581
Cross compiling to 'aarch64-unknown-linux-musl' doesn't work · Issue #1581 · axodotdev/cargo-dist
November 28, 2024 - # dist-workspace.toml [dist.github-custom-runners] aarch64-unknown-linux-gnu = "ubuntu-latest" aarch64-unknown-linux-musl = "ubuntu-latest" [dist.dependencies.apt] gcc-aarch64-linux-gnu = { version = '*', targets = ["aarch64-unknown-linux-gnu"] } musl-tools = { version = '*', targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"] } musl-dev = { version = '*', targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"] }
Author   simonsan
🌐
GitHub
github.com › lovell › aarch64-linux-musl-crosstools
GitHub - lovell/aarch64-linux-musl-crosstools: Cross-compiler toolchain to produce linuxmusl-arm64v8 binaries on linuxmusl-x64 · GitHub
Cross-compiler toolchain to produce linuxmusl-arm64v8 binaries on linuxmusl-x64 - lovell/aarch64-linux-musl-crosstools
Author   lovell
🌐
Musl
musl.cc
musl libc toolchains | static cross/native toolchains
musl.cc provides static cross- and native- musl-based toolchains for Linux, Windows, and macOS, targeting architectures like ARM, MIPS, PowerPC, RISC-V, S/390, and more.
🌐
Ubuntu
packages.ubuntu.com › jammy › musl-dev
Ubuntu – Details of package musl-dev in jammy
Homepage [musl.libc.org] libbtparse-dev · libhpdf-dev · libabsl-dev · libodil-dev · libc++-11-dev · libc++-12-dev · libc++-13-dev · libc++-14-dev · libc++-dev · libc++-15-dev · libc++-16-dev · dep: gcc-aarch64-linux-gnu [arm64] GNU C compiler for the arm64 architecture ·
🌐
Alpine Linux
pkgs.alpinelinux.org › contents
Package index - Alpine Linux packages
Contents filter · Alpine Linux | Privacy Policy | Apkbrowser Project
🌐
Arch Linux
archlinux.org › packages › extra › x86_64 › musl-aarch64
Arch Linux - musl-aarch64 1.2.5-6 (x86_64)
aarch64-linux-gnu-gcc (make) riscv64-linux-gnu-gcc (make) rust (make) View the file list for musl-aarch64 · View the soname list for musl-aarch64 · Copyright © 2002-2026 Judd Vinet, Aaron Griffin and Levente Polyák. The Arch Linux name and logo are recognized trademarks.
🌐
GitHub
github.com › rust-lang › stacker › issues › 80
`aarch64-unknown-linux-musl` target on amd64 Linux fails? · Issue #80 · rust-lang/stacker
May 15, 2023 - $ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc $ cargo build -p prqlc --release --target=aarch64-unknown-linux-musl Compiling cfg-if v1.0.0 Compiling once_cell v1.17.1 Compiling bitflags v1.3.2 Compiling linux-raw-sys v0.1.4 Compiling libc v0.2.140 Compiling utf8parse v0.2.1 Compiling lazy_static v1.4.0 Compiling memchr v2.5.0 Compiling concolor-override v1.0.0 Compiling concolor-query v0.3.3 Compiling anstyle v0.3.5 Compiling adler v1.0.2 Compiling gimli v0.27.2 Compiling serde v1.0.157 Compiling psm v0.1.21 Compiling pin-project-lite v0.2.9 error: failed to run
Published   May 15, 2023
Author   eitsupi