# Rust: error: linker `cc` not found — note: No such file or directory (os error 2)

**Code:** `error: linker `cc` not found` · **Category:** Rust · **Seen on:** Rust, Linux

Rust needs a C linker (gcc/clang) to produce executables, and none is installed.

## Meaning

Install a toolchain: Debian/Ubuntu `sudo apt install build-essential`, Fedora `sudo dnf install gcc`, Alpine `apk add build-base`, macOS `xcode-select --install`, Windows MSVC Build Tools (the "linker `link.exe` not found" variant). Docker images like `rust:slim` may need `build-essential` for crates with C code.

## Common causes

- build-essential/gcc not installed
- Minimal Docker image
- Windows without MSVC Build Tools (link.exe)
- macOS without Xcode CLT
- Cross compiling without a target linker

## Quick fix

1. `sudo apt install build-essential` (or OS equivalent)
2. Windows: install Visual Studio Build Tools (C++ workload)
3. Set the linker for cross targets in `.cargo/config.toml`

## Detailed fix by platform

### Linux

1. `which cc gcc ld && sudo apt install -y build-essential`

## How to diagnose

1. **Linker** — cc/link.exe?
2. **OS** — Which package?
3. **Cross** — Target linker?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/linker-cc-not-found)
