Rust on Windows: Kill the linker 'cc' not found error in 5 minutes

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: First encounter with the "red dragon"

\n\n

You've just started learning Rust. You downloaded the compiler, wrote your first hello.rs, run cargo build... And then the terminal explodes with a red message: "linker 'cc' not found". Sound familiar? If you're working on Windows 10 using WSL with Debian, this error is a classic "hello" from the world of system programming.

\n\n

Don't panic. This is not a Rust bug, it's a feature of environment configuration. In this article, we will not only solve this problem once and for all, but also talk about how to optimize the build process so your code compiles faster. After all, Rust is famous for its performance, and we must give the compiler the best tools to work with.

\n\n

Why does the "linker 'cc' not found" error occur?

\n\n

To understand the enemy, you need to know it. Rust is a compiled language. When you run cargo build, the rustc compiler turns your code into machine code. But the final stage is linking (assembling object files into an executable). This work is done by an external program — the linker.

\n\n

By default, on Linux systems (including WSL Debian), Rust looks for the cc linker. This is a symbolic link that usually points to gcc or clang. If your WSL system does not have a C compiler (GCC or Clang) installed, the cc link is missing. Rust doesn't know what to use to link your project and throws a fatal error.

\n\n

Root of the problem: WSL Debian — minimal installation

\n

When you install WSL Debian from the Microsoft Store, you get a bare system. It has neither GCC, nor Make, nor other developer tools. Rust does not include a C linker — this is the responsibility of the system environment.

\n\n

Method #1: Quick fix (install GCC)

\n\n

The simplest and correct way is to install the standard set of C development tools. Open your WSL Debian terminal and run:

\n\n
sudo apt update\nsudo apt install build-essential
\n\n

The build-essential package is a meta-package that pulls in gcc, g++, make, and most importantly, creates the /usr/bin/cc link. After installation, check:

\n\n
which cc\n# Should show: /usr/bin/cc
\n\n

Now run cargo build again — the error will be gone. Rust found the linker.

\n\n

Why is this important for performance?

\n

By using the standard GCC, you get a stable and optimized linker. Rust will build your project with minimal overhead. Optimization starts with the right toolset.

\n\n

Method #2: Fine-tuning (install Clang)

\n\n

If you're a fan of LLVM and Clang (and Rust also uses LLVM under the hood), you can install it instead of GCC. This can give a slight speed boost to linking on some projects.

\n\n
sudo apt install clang lld\n# Create the link manually if it doesn't exist\nsudo ln -s /usr/bin/clang /usr/bin/cc
\n\n

Verification:

\n
cc --version\n# Should show Clang
\n\n

Important: LLD (LLVM Linker) is often faster than the classic GNU ld. For large Rust projects, this can reduce build time by 10-20%. Installing Clang is not just a bug fix, it's compilation performance optimization.

\n\n

Method #3: Workaround (specify linker manually)

\n\n

There are situations where you don't want to install GCC or Clang (for example, on a production server with restrictions). You can explicitly tell Rust which linker to use. But keep in mind: without an installed linker, this method won't work.

\n\n

Create a file ~/.cargo/config.toml (or /.cargo/config.toml for global settings):

\n\n
[target.x                

Blogs

Book Recommendations