Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rust compiler can't find crate for 'std'

I recently downloaded and unpacked the Rust Language from this site (Linux 64-bit).

I then installed Rust using the given script in the download install.sh:

root@kali:~# /root/rust-1.9.0-x86_64-unknown-linux-gnu/install.sh
install: uninstalling component 'rustc'
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rustc'
install: installing component 'rust-std-x86_64-unknown-linux-gnu'
install: installing component 'rust-docs'
install: installing component 'cargo'

    Rust is ready to roll.

I am trying to install a crate with cargo, but I keep running into this error:

root@kali:~# cargo install racer
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling winapi v0.2.7
   Compiling bitflags v0.5.0
error: can't find crate for `std` [E0463]
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: can't find crate for `std` [E0463]
error: aborting due to previous error
error: failed to compile `racer v1.2.10`, intermediate artifacts can be found at `/root/target-install`

cargo install cargo-edit failed with the same result as above, so it's not limited to one particular package.

Even putting a simple program:

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

in a file named hello.rs and running rustc hello.rs does not compile; it gives the same error: error: can't find crate for 'std' [E0463].

The download came with a directory named rust-std-x86_64-unknown-linux-gnu, which I assume is the std crate. How do I instruct rustc to find this directory when trying to locate the std crate?

like image 920
ljeabmreosn Avatar asked Jun 26 '16 17:06

ljeabmreosn


2 Answers

The following will work for the simplest of compilations. Assuming you extracted the tar file to, say

$HOME/rust-1.10.0-x86_64-unknown-linux-gnu

Then run

arch=x86_64-unknown-linux-gnu
dl=$HOME/rust-1.10.0-$arch
$dl/rustc/bin/rustc -L $dl/rustc/lib \
    -L $dl/rust-std-$arch/lib/rustlib/$arch/lib \
    hello.rs

But I'm sure a better way would be to run rustup as Chris Morgan suggest.

Coupla more points

  1. You shouldn't compile code as root.
  2. You may have to relogin or run bash -l to get the environment setup by rustup.

(Fellow rust newb here)

like image 120
Matthew Hannigan Avatar answered Sep 21 '22 16:09

Matthew Hannigan


For me (Arch Linux) removing system's Rust fixed the issue.

pacman -Rc rust

I think there was a conflict among user installed Rust and system installed one.

like image 29
Kazuya Gosho Avatar answered Sep 21 '22 16:09

Kazuya Gosho