Rust编译器找不到“std”板条箱。

10

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

然后,我使用下载的install.sh脚本安装了Rust:

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.

我正在尝试使用cargo安装一个crate,但是一直遇到以下错误:

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 失败,结果和上面一样,因此这不仅限于一个特定的包。

即使是放置一个简单的程序:

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

在名为 hello.rs 的文件中运行 rustc hello.rs 无法编译;它会给出相同的错误:error: can't find crate for 'std' [E0463]
下载包含一个名为 rust-std-x86_64-unknown-linux-gnu 的目录,我认为这是 std crate。如何指示 rustc 在尝试查找 std crate 时找到此目录?

除了Racer之外,您能否编译Rust代码?例如,尝试cargo install cargo-edit。虽然Racer需要std的源代码,但错误消息听起来像是编译器找不到std的二进制文件,因此它甚至无法编译Racer。 - user395760
1
@delnan:显然,即使是“Hello, world!”也无法编译,因此我倾向于认为这里的问题是rustc不知道std crate在哪里。 - Matthieu M.
2
你可以尝试使用rustup - Chris Morgan
@Chris Morgan谢谢你提供rustup的建议;我会去研究一下! - ljeabmreosn
3个回答

3
Alpine Linux中,更改目标后,这个命令帮助我重新安装rust-std:
rustup component add rust-std

这个答案没有正确回答问题,因为提问者正在使用安装脚本,而不是Rustup。您能否提供更多的上下文信息? - naiveai
构建WASM的leptos示例项目时,遇到了关于cargo找不到"std"的错误。通过指定目标并为wasm32目标安装rust-std,问题得到解决:rustup component add rust-std --target wasm32-unknown-unknown。每次交叉编译时,无论是嵌入式、WASM还是为其他机器编译,都需要继续安装rust-std。 - undefined

2
以下内容适用于最简单的编译。 假设您将tar文件提取到了某个位置。
$HOME/rust-1.10.0-x86_64-unknown-linux-gnu

然后运行。
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

但我确信更好的方法是像Chris Morgan建议的那样运行rustup。

还有几点需要注意:

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

(这里是一个Rust新手)


1

对于我来说(Arch Linux),移除系统的Rust解决了这个问题。

pacman -Rc rust

我认为用户安装的Rust和系统安装的Rust之间存在冲突。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接