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.
cargo output
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
Terminal
# 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
# .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.
Related guides
Rust "error: linking with `cc` failed" in CIFix Rust "error: linking with `cc` failed: exit status: 1" in CI - undefined references or missing system lib…
Rust "Could not find directory of OpenSSL" - openssl-sys in CIFix the openssl-sys "Could not find directory of OpenSSL installation" error in CI - install libssl-dev and p…
Self-Healing CI: Missing System Packages and Setup GapsA missing system library or tool fails the build until someone installs it. See the manual fix and how self-h…