How To Fix Rust Error “linker ‘cc’ not found” On Linux
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
$ sudo dnf install cmake
On CentOS, RHEL:
$ sudo yum install cmake
$ sudo zypper install cmake
Installing gcc solved the problem for me.
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.