我收到以下错误消息:
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if`
To learn more, run the command again with --verbose.
当我运行这个命令时:
cargo build --target wasm32-unknown-unknown
板条箱有一个特殊之处,例如core
and std
也就是说,由于它们无处不在,因此它们在某些预编译版本中使用,而不是像其他板条箱那样每次都从源代码构建。但是,只有在交叉编译时(即使用--target
flag).
本质上有两个选项可以解决这个问题,并且它们也在rustc --explain E0463
(网络版):
- [if] You are cross-compiling for a target which doesn’t have
std
[or core
] prepackaged. Consider one of the following:
- 添加预编译版本
std
[or core
] with rustup target add
- 建筑
std
[or core
] 来自带有货物构建的源代码-Z build-std
第一个选项(@Ivan 和 @Jmb 也已经指出)可能是显而易见的
一:
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown
第二个选项仅适用于 Nightly 编译器,并且需要rust-src
成分。但如果您不想安装每个目标,或者您正在针对自定义目标进行编译(即--target
带有一些 JSON 文件):
rustup +nightly component add rust-src
cargo +nightly build --target wasm32-unknown-unknown -Z build-std=core
附带说明一下,与当前稳定版本 (1.52) 相比,当前 Nightly Rust 版本中的错误消息已得到改进。每晚编译器将打印:
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
= help: consider building the standard library from source with `cargo build -Zbuild-std`
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)