newspaint

Documenting Problems That Were Difficult To Find The Answer To

Where Is The Std Crate Located In A Rust Installation

I downloaded Rust (the programming language) from the Rust downloads page. Specifically I downloaded the 64-bit Linux .tar.gz file and then extracted it to /opt/ on my filesystem and symlinked /opt/rust to the untarred directory.

However when I went to compile a test Rust program I got the following error:

$ /opt/rust/rustc/bin/rustc test.rs
error: can't find crate for `std` [E0463]
error: aborting due to previous error

I searched for the std crate by running:

$ find /opt/rust/ -name 'libstd*'
/opt/rust/rustc/lib/libstd-d16b8f0e.so
/opt/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d16b8f0e.so
/opt/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d16b8f0e.rlib
/opt/rust/rust-docs/share/doc/rust/html/src/std/up/src/libstd

I tried then compiling my Rust program using the first path, “/opt/rust/rustc/lib/“:

$ /opt/rust/rustc/bin/rustc -L /opt/rust/rustc/lib test.rs
error:error: can't find crate for `core` which `std` depends on [E0463]
error:error: aborting due to previous error

So, where is libcore?

$ find /opt/rust/ -name 'libcore*'
/opt/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d16b8f0e.rlib
/opt/rust/rust-docs/share/doc/rust/html/src/core/up/src/libcore

I then tried compiling using the path to libcore.

$ /opt/rust/rustc/bin/rustc -L /opt/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib test.rs
$

Success!

If you want to pass command line options for rustc to cargo you can do it as follows:

$ RUSTFLAGS="-L /opt/rust/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" cargo
$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: