Skip to content
Latchkey

Rust Cross-Compilation Linker Missing in CI

You added the cross-compilation target and rustc compiled the code, but the link step needs a cross-linker for the foreign architecture that isn’t installed. The host cc can’t link a binary for a different CPU target.

What this error means

A --target <foreign> build gets through compilation, then fails at link with linker <arch>-gcc not found (or a default cc producing wrong-architecture errors). The target’s std is installed, but the cross C toolchain/linker is missing.

cargo output
error: linker `aarch64-linux-gnu-gcc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `app` (bin "app") due to 1 previous error

Common causes

No cross-linker for the target architecture

Cross-compiling to aarch64/arm/musl needs a matching cross GCC (or lld) and often the target’s C runtime. Adding the rustc target alone doesn’t install the linker.

Cargo not told which linker to use

Even with the cross-linker installed, Cargo defaults to cc. Without a per-target linker = ... in .cargo/config.toml, it invokes the host linker for the foreign target.

How to fix it

Install the cross toolchain and point Cargo at it

Add the cross GCC, then set the linker for that target.

Terminal
apt-get update && apt-get install -y gcc-aarch64-linux-gnu
# .cargo/config.toml
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

Or use a cross-build tool

Tools like cross (Docker-based) or cargo-zigbuild bundle the right toolchain so you don’t configure linkers by hand.

Terminal
cargo install cross --git https://github.com/cross-rs/cross
cross build --target aarch64-unknown-linux-gnu --release

How to prevent it

  • Install the matching cross GCC/linker for every target you build.
  • Set a per-target linker in .cargo/config.toml.
  • Use cross or cargo-zigbuild for hands-off cross toolchains in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →