Home Rust How To Fix Rust Error “linker ‘cc’ not found” On Linux

How To Fix Rust Error “linker ‘cc’ not found” On Linux

By sk
Published: Updated: 57.2K views

Today I was testing a network bandwidth utilization tool called Bandwhich on my Ubuntu VM. That tool is developed in Rust programming language, so I tried to install it using Cargo package manager. In the middle of compilation process, I encountered with the following error:

Updating crates.io index
Installing bandwhich v0.6.0
Compiling libc v0.2.66
error: linker `cc` not found
|
= note: No such file or directory (os error 2)

error: aborting due to previous error

error: failed to compile `bandwhich v0.6.0`, intermediate artifacts can be found at `/tmp/cargo-installrqSeTB`

Caused by:
could not compile `libc`.

To learn more, run the command again with --verbose.

As you can see in the above output, Cargo couldn't find cc compiler program to compile the given application. Since Rust does not include its own linker yet, you need to have a C compiler like gcc installed to act as the linker.

To install gcc on Ubuntu, simply run:

$ sudo apt install build-essential

If you're on different Linux OS, refer the following link to install development tools which includes necessary applications, such as GNU GCC C/C++ compilers, make, and debuggers etc.

After installing gcc, the error "linker cc not found" is gone! And then I can be able to install the application without any issues.

If you still get the same error even GCC is already installed, install cmake and try again. Cmake is available in the official repositories of most Linux distributions.

To install Cmake on Arch Linux, enable [Extra] repository and run:

$ sudo pacman -S cmake

On Debian, Ubuntu, Linux Mint:

$ sudo apt install cmake

On Fedora, RHEL, CentOS, AlmaLinux, and Rocky Linux:

$ sudo dnf install cmake

On openSUSE:

$ sudo zypper install cmake

Installing gcc solved the problem for me.

Update:

In NixOS, this problem will not solve even after installing "GCC" and "make". As mentioned in this GitHub thread, you should try this with nix-shell, instead of nix-env.

Good luck!

Resource:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More