简体   繁体   English

Rust 找不到“标准”的“板条箱”

[英]Rust can't find 'crate' for 'std'

I'm trying to get a.wasm file via RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown but get the error:我正在尝试通过RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown获取 a.wasm 文件,但出现错误:

error[E0463]: can't find crate for `std`

When i type rustup target add wasm32-unknown-unknown i get:当我输入rustup target add wasm32-unknown-unknown我得到:

info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date

I installed Rust and Rustup separate via chocolatey.我通过巧克力分开安装了 Rust 和 Rustup。

  • rustc 1.58.0锈病 1.58.0
  • rustup 1.24.3生锈 1.24.3
  • info: The currently active rustc version is rustc 1.60.0-nightly (5e57faa78 2022-01-19)信息:当前活动的rustc版本是rustc 1.60.0-nightly (5e57faa78 2022-01-19)

You need to add the wasm32-unknown-unknown target for the nightly toolchain if that's what you are using:如果您正在使用,则需要为夜间工具链添加 wasm32-unknown-unknown 目标:

rustup target add --toolchain nightly wasm32-unknown-unknown

I suffered the same symptoms after initialized a new cargo project on macOS but my problem was not adding to the wrong toolchain.在 macOS 上初始化一个新的 cargo 项目后,我遇到了同样的症状,但我的问题不是添加到错误的工具链中。

In my case, the problem was multiple cargo binaries.就我而言,问题是多个货物二进制文件。 I discovered this after running which cargo and seeing it installed via homebrew.我在运行which cargo并看到它通过自制软件安装后发现了这一点。 I did rustup self uninstall (perhaps unnecessary), homebrew uninstall rust and, then reinstalled rust according to the official docs and wasm32-unknown-unknown and then the cargo build --release --target wasm32-unknown-unknown command worked as expected.我做了rustup self uninstall (也许没有必要), homebrew uninstall rust ,然后根据官方文档wasm32-unknown-unknown重新安装 rust,然后cargo build --release --target wasm32-unknown-unknown命令按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM