Rust "linker `cc` not found" - Fix Missing Linker in CI
rustc uses the system C compiler (cc) as its linker, and there is no cc on the runner. The final link step of the build cannot run until a C toolchain is installed.
What this error means
Compilation gets through code generation, then fails at the link step with error: linker cc not found. The Rust toolchain itself is fine - only the OS-level linker is missing, common on slim/Alpine images.
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: could not compile `app` (bin "app") due to 1 previous errorCommon causes
No C toolchain on a minimal image
Slim and Alpine base images omit a C compiler to stay small. rustc has nothing to invoke as cc for the link step.
rustup installed without a system compiler
Installing Rust via rustup does not install a linker. On a bare image you must add gcc/build-essential separately.
How to fix it
Install the C toolchain
# Debian/Ubuntu
apt-get update && apt-get install -y build-essential
# Alpine
apk add --no-cache build-base
# RHEL/Fedora
dnf groupinstall -y "Development Tools"Or use an alternative linker
If you install lld or mold, point Cargo at it instead of cc.
# .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]How to prevent it
- Bake
build-essential/build-baseinto images that compile Rust. - Use the official
rustDocker image, which ships a working linker. - Document the OS-level build dependencies your project needs.