Error running hello-rust after standalone installation: where does cargo look for libraries?

Hi, I just installed Rust using a standalone installer (x86_64-unknown-linux-gnu). Everything appears to be fine:

$ rustc --version
rustc 1.61.0 (fe5b13d68 2022-05-18)
$ cargo --version
cargo 1.61.0 (a028ae4 2022-04-29)

However, the hello-rust example fails with this error:

$ cargo run 
   Compiling hello-rust v0.1.0 ([...]/hello-rust)
error[E0463]: can't find crate for `std`

error: cannot find macro `println` in this scope
 --> src/main.rs:2:5
  |
2 |     println!("Hello, world!");
  |     ^^^^^^^

error: requires `sized` lang_item

For more information about this error, try `rustc --explain E0463`.
error: could not compile `hello-rust` due to 3 previous errors

Why is this happening? Where does cargo look for libraries? What paths do I need to configure exactly, and how?

Manual invocation:

$ rustc -L ~/rust/rustc/lib/ -L ~/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/ ./main.rs

works just fine.

My ~/rust/ is a symlink to $HOME/rust-1.61.0-x86_64-unknown-linux-gnu/. I added ~/rust/rustc/bin/ to my $PATH, and created a symlink to cargo inside my $HOME/bin.

Thanks!

It's not really cargo looking for the default libraries, just rustc looking in its root. You can run rustc --print sysroot to see where it thinks that is, and then lib/rustlib/$TARGET/lib under that.

edit: even better, rustc --print target-libdir

1 Like

Ok, so rustc --print sysroot prints out $HOME/rust-1.61.0-x86_64-unknown-linux-gnu/rustc (i.e. I replaced my homedir path here with $HOME), which I think is fine.

However rustc --print target-libdir prints out $HOME/rust-1.61.0-x86_64-unknown-linux-gnu/rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib which does not exist! I only have its parent directory, i.e.: $HOME/rust-1.61.0-x86_64-unknown-linux-gnu/rustc/lib/rustlib/x86_64-unknown-linux-gnu/ which in turn contains 2 other dirs: bin and codegen-backends, but no lib!

Please check for yourself in the release file: https://static.rust-lang.org/dist/rust-1.61.0-x86_64-unknown-linux-gnu.tar.gz .

That release tarball is not meant to be used directly as extracted. It contains a bundle of multiple components that we also package separately, and they will be properly combined when you actually install it. So please use the install.sh script with a destination --prefix of your choice.

3 Likes

Thanks, it did the trick! :slight_smile:

BTW this is a non-root installation: shall I expect any problems in the future?

Non-root is fine -- that's exactly how rustup would install it for you, in your home.