Rust 编译器找不到“std”的箱子

lje*_*osn 7 rust rust-cargo

我最近从这个站点(Linux 64 位)下载并解压了 Rust 语言。

然后我使用下载中的给定脚本安装了 Rust 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.
Run Code Online (Sandbox Code Playgroud)

我正在尝试安装带有货物的板条箱,但我一直遇到此错误:

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`
Run Code Online (Sandbox Code Playgroud)

cargo install cargo-edit 失败,结果与上述相同,因此它不限于一个特定的包。

甚至放一个简单的程序:

fn main() {
    println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)

在名为hello.rs和运行的文件rustc hello.rs中不编译;它给出了同样的错误:error: can't find crate for 'std' [E0463]

下载附带了一个名为 的目录rust-std-x86_64-unknown-linux-gnu,我认为它是 std crate。尝试定位 std crate 时,如何指示 rustc 找到此目录?

Mat*_*gan 2

以下内容适用于最简单的编译。假设您将 tar 文件解压到

$HOME/rust-1.10.0-x86_64-unknown-linux-gnu
Run Code Online (Sandbox Code Playgroud)

然后运行

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
Run Code Online (Sandbox Code Playgroud)

但我确信更好的方法是按照 Chris Morgan 的建议运行 rustup。

耦合 更多积分

  1. 您不应该以 root 身份编译代码。
  2. 您可能需要重新登录或运行 bash -l 才能通过 rustup 设置环境。

(这里是 Rust 新手)