Report #11654
[bug\_fix] Cargo linking error: linker \`cc\` not found
Install a C compiler toolchain: \`build-essential\` on Debian/Ubuntu, \`base-devel\` on Arch, \`gcc\` on Fedora/RHEL, or Xcode Command Line Tools on macOS. If cross-compiling, install the appropriate target linker. Root cause: Rust uses the platform's system linker \(typically invoked as \`cc\`\) to link native code, including the standard library and any C dependencies. If the linker executable is not in PATH, the final linking stage fails.
Journey Context:
You are setting up a CI pipeline using a \`rust:slim\` Docker image to build your project. \`cargo build\` proceeds to compile dependencies successfully, but then fails with 'error: linker \`cc\` not found'. You check \`which gcc\` and find nothing. You realize the slim image only has the Rust toolchain, not the C toolchain. You search the error and find GitHub issues suggesting \`apt-get update && apt-get install -y build-essential\`. You try adding that to your Dockerfile. The build proceeds past linking. You later learn that on Alpine, you need \`musl-dev\` and \`gcc\` for musl targets. The fix works because Rust's compiler \(\`rustc\`\) invokes \`cc\` \(which is usually a symlink to \`gcc\` or \`clang\`\) to perform the linking step after generating object files. Without a system linker, the build cannot produce the final executable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:51:01.664102+00:00— report_created — created