19

After installing First time rust on ubuntu try to run this program.

fn main() {
    println!("Hello, world!");
}

Error:

$ cargo run
   Compiling test1 v0.1.0 (/home/saad/Documents/Rust/test1)
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `test1`.
Boiethios
  • 38,438
  • 19
  • 134
  • 183
M Saad Sajid
  • 443
  • 1
  • 3
  • 9
  • 1
    How did you install Rust? If you installed it with rustup, don't forget to install `build-essential`: `# apt install build-essential` – Boiethios Nov 21 '19 at 16:43
  • "sudo apt-get install update" "sudo apt-get install crul" I use these commands, then I use this command "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" And Installation starts. – M Saad Sajid Nov 21 '19 at 16:48
  • Well, so as I said, you must install the `build-essential` package – Boiethios Nov 21 '19 at 16:57
  • 2
    Does this answer your question? [How do I fix the Rust error "linker 'cc' not found" for Debian on Windows 10?](https://stackoverflow.com/questions/52445961/how-do-i-fix-the-rust-error-linker-cc-not-found-for-debian-on-windows-10) – Boiethios Nov 21 '19 at 17:03

3 Answers3

24

As mentioned in the message, the linker 'cc' is missing. You can install it using apt-get:

sudo apt-get install gcc

After the installation completes, the problem should be solved.

Reinis Mazeiks
  • 1,168
  • 1
  • 10
  • 21
M Saad Sajid
  • 443
  • 1
  • 3
  • 9
  • For WSL installations please follow the accepted answer on this [question](https://stackoverflow.com/questions/62215963/how-to-install-gcc-and-gdb-for-wslwindows-subsytem-for-linux) – Leela Venkatesh K Apr 25 '23 at 08:43
  • What if you get this on a Windows machine (not WSL)? I'm seeing this on GitHub Actions? Surely there's a way to cross-compile, no? – Andrew Arnott Jul 03 '23 at 00:52
8

Your system is missing a C linker, which Rustup assumes that you already have. You can install one (among other potentially useful tools, like make) via the following command:

sudo apt install build-essential

Newbyte
  • 2,421
  • 5
  • 22
  • 45
  • @FrenchBoiethios That is very much true. My apologies, I'm not very well-versed in how cases like these usually are handled on Stackexchange. Would it be better to not answer the question in the case that there is a linked duplicate (which this question doesn't seem to be flagged as any more?)? – Newbyte Nov 23 '19 at 23:59
2

This error happens mostly either linux or wsl. You can fix it by running the following command :

sudo apt install build-essential

If still issue persists, please go on to install gcc as below

sudo apt-get install gcc

If gcc ended with some error, please go on with the following command also (This is purely optional only)

apt-get update --fix-missing
Anand Raja
  • 2,676
  • 1
  • 30
  • 35