Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

error: linker `cc` not found (No such file or directory, os error 2) when building Rust: how to fix it

error: linker `cc` not found with note: No such file or directory (os error 2) means rustc compiled your code and then could not find the C compiler it uses to link it. On Linux, rustc calls cc as its linker driver, and a fresh machine or a slim container may have none. Install a C compiler (build-essential on Debian and Ubuntu, gcc and musl-dev on Alpine), or build in the official rust Docker image, which ships gcc.

By Livops team, the people who build and run LivopsUpdated

As rustc prints it when the C compiler it links with is missing[1][2][3]:

$ cargo build --release
   Compiling proc-macro2 v1.0.95
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

The crate in the Compiling line varies: the error comes from the first thing that has to be linked. That is often not your own code but a dependency’s build script, which Cargo compiles into an executable and runs before building the package[6].

This page explains why rustc needs cc, how to install it on each system, the Docker images that already have it, and how to name another linker. The last section shows where it surfaces on Livops.

What does the error mean?

rustc compiles Rust into object files, then calls a linker to join them into one binary. Unless you say otherwise, the linker is inferred from the target[4]. On Unix-like targets such as x86_64-unknown-linux-gnu, the C compiler, cc or clang, is used as that “linker”, serving as a linker driver: it runs the actual linker with the flags needed to link against system libraries like libc[4]. For those targets the default program is literally cc[2].

When rustc tries to start that program and the system says it does not exist, rustc stops with linker `cc` not found, and puts the operating system’s own error under it as a note[2][1]. No such file or directory (os error 2) is that error: the system’s message, then its number, in the form Rust prints every operating-system error[3].

So the toolchain itself is fine. The machine has rustc and cargo, typically from rustup, but no C compiler. The Rust book says it plainly: you also need a linker, and if you get linker errors you should install a C compiler, which typically includes one[5]. A C compiler is also needed because some common Rust packages depend on C code[5]; build scripts often compile it with the cc crate[6].

Two neighbours of this error mean something else:

  • could not exec the linker `cc` — the program exists but could not be started, for a reason other than not being found[1][2].
  • linking with `cc` failed: exit status: 1 — cc ran, and the link itself failed[1]. The linker’s own output follows it, and usually names a missing library.

The fix: install a C compiler

Debian and Ubuntu

sudo apt-get update
sudo apt-get install -y build-essential

build-essential depends on gcc, g++, make, libc6-dev and dpkg-dev, on Debian 13 (trixie)[8] and Ubuntu 24.04 (noble) alike[9]. The Rust book names it for Ubuntu[5]. The official slim rust image installs only gcc and libc6-dev for C[12], which is enough for rustc to link; g++ and make matter for crates that build C++ or run make.

Alpine

apk add --no-cache gcc musl-dev

The official rust Alpine image installs exactly these two[13], and its Rust targets the musl C library, for example x86_64-unknown-linux-musl[13].

Other Linux distributions

The Rust book’s advice is to install GCC or Clang, according to your distribution’s documentation[5].

macOS

xcode-select --install

The Rust book gives this command for getting a C compiler on macOS[5].

Windows

With the default MSVC toolchain, the missing linker is link.exe, not cc. rustc then adds notes that the MSVC targets depend on the MSVC linker, that Visual Studio 2017 or later, or Build Tools for Visual Studio, must be installed with the Visual C++ option, and that VS Code is a different product[1][2]. Visual Studio provides the linker and the native libraries; the Rust book points to rustup’s Windows MSVC guide for that step[5].

Or build in the official rust image

The Docker images published as rust already contain a C compiler, in every variant:

Image Based on C toolchain in it
rust:1, rust:latest buildpack-deps:trixie[11] gcc, g++, make, libc6-dev and many -dev libraries[14]
rust:slim debian:trixie-slim[12] gcc and libc6-dev only[12]
rust:alpine alpine:3.24[13] gcc and musl-dev[13]

The tags are from the official image list: 1 and latest are the trixie image, slim is slim-trixie, and alpine is alpine3.24[10]. Today they carry Rust 1.100.1[10][11].

So the error inside Docker usually means the image is not one of these: a plain debian, ubuntu or alpine base with Rust added by rustup, and no compiler. Either add the packages above to it, or start the build stage from rust. A multi-stage build compiles in the rust image and copies only the binary into a small one:

FROM rust:1 AS build
WORKDIR /src
COPY . .
RUN cargo build --release

FROM debian:trixie-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
 && rm -rf /var/lib/apt/lists/*
COPY --from=build /src/target/release/myapp /usr/local/bin/myapp
CMD ["myapp"]

myapp stands for your package’s binary name. Both stages are Debian trixie[10][15], so the binary runs against the same glibc it was linked with. rust:slim has no g++ or make[12]: a crate that compiles C++ needs the full image, or those packages added.

Name another linker

If a C compiler is installed under another name, for example gcc but no cc, tell rustc which program to call. -C linker takes the path to the linker executable[4]:

rustc -C linker=gcc src/main.rs

With Cargo, put it in .cargo/config.toml; Cargo passes target.<tuple>.linker to rustc as -C linker[7]:

[target.x86_64-unknown-linux-gnu]
linker = "gcc"

The same key as an environment variable is CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=gcc: keys go upper case, with dots and dashes turned into underscores[7]. This is also how you set a cross-linker such as arm-none-eabi-gcc for another target[7].

How to confirm the fix locally

Check that a C compiler answers under the name rustc looks for:

cc --version

Then build again:

cargo build --release

To reproduce the server, build in the image it uses. rust:slim has gcc and libc6-dev and nothing more for C[12], so a crate that needs more fails there too:

docker run --rm -v "$PWD":/src -w /src rust:slim cargo build --release

On Livops

  • Where it shows. The compile is the build step, so the deploy stops as build_failed with cargo’s error in the build log; the previous version keeps running. The cabinet shows the error code with the most useful line of the log under it. See Build failed.
  • What Livops runs. Rust is one of the detected frameworks: for a Cargo.toml project the install step is cargo fetch and the build is cargo build. See Frameworks and livops.json.
  • The C compiler. The Livops docs do not say which C toolchain the Rust build has. If your build stops with linker `cc` not found, or a crate needs a C library the build does not have, build it yourself with a Dockerfile.
  • Your own Dockerfile. If the repository has a Dockerfile, it is used. In livops.json, "builder": "dockerfile" says so explicitly; it is read when the project is created. Start the build stage from rust:1 as above, and listen on the port in the PORT variable for a web app.
  • The first build is slow. A Rust web app takes 8–9 minutes on its first build and about a minute after a code change, and a build may run ten minutes. If it runs out of time, deploy again: what was compiled stays in the project’s cache. See Time ran out.
  • The assistant explains. Next to the failed build, the assistant’s button reads the log and tells you what happened and how to fix it. See AI assistant.

What a Rust web app needs in production, and what Livops does with a Cargo.toml, is in Rust hosting.

Questions

Why does Rust need a C compiler at all?

rustc compiles Rust itself, but on Unix-like targets such as x86_64-unknown-linux-gnu it uses the C compiler, cc or clang, as its linker driver. The C compiler then calls the real linker with the flags needed to link against the system libraries such as libc. Without it, nothing can be linked, not even a build script.

Which package do I install on Ubuntu or Debian?

build-essential. It pulls in gcc, g++, make, libc6-dev and dpkg-dev, which is enough for rustc to link and for most crates that compile C code. On Alpine, install gcc and musl-dev, the two packages the official rust Alpine image adds.

Does the official rust Docker image include gcc?

Yes, every variant. The default image, rust:1 or rust:latest, is built on buildpack-deps:trixie, which installs gcc, g++, make and many development libraries. rust:slim installs gcc and libc6-dev only, and the Alpine images install gcc and musl-dev.

I have gcc but no cc. Can I point Rust at gcc?

Yes. Pass -C linker=gcc to rustc, or with Cargo set linker = "gcc" under [target.x86_64-unknown-linux-gnu] in .cargo/config.toml, or the environment variable CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=gcc. Cargo passes that value to rustc as -C linker.

What does linking with cc failed mean instead?

That is a different error: cc was found and ran, but the link itself failed, for example because a system library is missing. The lines under it are the linker's own output, and they name what it could not find.

How do I fix it on macOS or Windows?

On macOS, run xcode-select --install, the command the Rust book gives for getting a C compiler. On Windows with the default MSVC toolchain the missing linker is link.exe, which Visual Studio or the Build Tools for Visual Studio with the Visual C++ option provide, and rustc says so in its notes.

Does Livops build Rust with a C compiler?

The Livops docs do not say which C toolchain the Rust build has. If your build stops with this error, build with a Dockerfile that starts from the official rust image, which ships gcc, and set builder to dockerfile in livops.json.

Sources

  1. Rust source — compiler/rustc_codegen_ssa/src/diagnostics.rs (github.com). Checked .
  2. Rust source — compiler/rustc_codegen_ssa/src/back/link.rs (github.com). Checked .
  3. Rust source — library/core/src/io/error.rs (github.com). Checked .
  4. The rustc book — Codegen Options (doc.rust-lang.org). Checked .
  5. The Rust Programming Language — Installation (doc.rust-lang.org). Checked .
  6. The Cargo Book — Build Scripts (doc.rust-lang.org). Checked .
  7. The Cargo Book — Configuration (doc.rust-lang.org). Checked .
  8. Debian — Package build-essential (trixie) (packages.debian.org). Checked .
  9. Ubuntu — Package build-essential (noble) (packages.ubuntu.com). Checked .
  10. Docker Official Images — rust tags (github.com). Checked .
  11. rust-lang/docker-rust — stable/trixie/Dockerfile (github.com). Checked .
  12. rust-lang/docker-rust — stable/trixie/slim/Dockerfile (github.com). Checked .
  13. rust-lang/docker-rust — stable/alpine3.24/Dockerfile (github.com). Checked .
  14. docker-library/buildpack-deps — debian/trixie/Dockerfile (github.com). Checked .
  15. Docker Official Images — debian tags (github.com). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your Rust app

Got a question? — @livops_uz