简体   繁体   English

错误 [E0463]: can't find crate for std... 如何在 x64 Windows 机器上编译 Rust x32?

[英]Error[E0463]: can't find crate for std... how to compile Rust x32 in a x64 Windows machine?

I'm on Windows 10 x64.我在 Windows 10 x64 上。 I have Visual Studio 2019 installed, which allows me to compile C and C++ for both x32 and x64 without problems.我安装了 Visual Studio 2019,它允许我为 x32 和 x64 编译 C 和 C++ 而不会出现问题。

Now, for Rust, I have the stable-x86_64-pc-windows-msvc toolchain installed through rustup, which allows me to compile x64 binaries just fine.现在,对于 Rust,我通过 rustup 安装了stable-x86_64-pc-windows-msvc工具链,它允许我很好地编译 x64 二进制文件。

In an attempt to compile Rust x32, I installed the stable-i686-pc-windows-msvc , but when I run cargo test --target i686-pc-windows-msvc , it gives me error[E0463]: can't find crate for std .在尝试编译 Rust x32 时,我安装了stable-i686-pc-windows-msvc ,但是当我运行cargo test --target i686-pc-windows-msvc时,它给了我error[E0463]: can't find crate for std

How can I fix this?我怎样才能解决这个问题?

This seems to be a misunderstanding on what is toolchain and what is target .这似乎是对什么是toolchain和什么是target的误解。

The code is always being built for some target triple - it's usually fully defined by the system in question (Windows systems are an exception, since they have two kinds of target triples - *-msvc and *-gnu , depending on the C compiler and linker).代码总是为某些目标三元组构建 - 它通常由相关系统完全定义(Windows 系统是一个例外,因为它们有两种目标三元组 - *-msvc*-gnu ,具体取决于 C 编译器和链接器)。

When you install the toolchain, using the安装工具链时,使用

rustup toolchain install toolchain-name

its name is defined as compiler_version - target_triple , eg stable-x86_64-pc-windows-msvc .它的名字被定义为compiler_version - target_triple ,例如stable-x86_64-pc-windows-msvc The target triple here is the one which was used to build the compiler, ie it is defined by the host system - the one which runs the compilation process;这里的目标三元组是用来构建编译器的,即它是由主机系统定义的——运行编译过程的那个; therefore, almost always all the installed toolchains will differ only in version part - eg, if you need some code to use the nightly-only features, you'll install nigtly-*triple* alongside the stable-*triple* .因此,几乎所有已安装的工具链都只会在version部分有所不同 - 例如,如果您需要一些代码来使用仅夜间功能,您将安装nigtly-*triple*stable-*triple*

When you add the target, using the添加目标时,使用

rustup target add target-name

its name is just the target triple, without reference to the compiler version.它的名字只是目标三元组,与编译器版本无关。 In this case, the triple is what is used by the compiler, building your own code , and for the prebuilt standard library;在这种情况下,三元组是编译器使用的,用于构建您自己的代码,并用于预构建的标准库; and that's what you need to use when you're using the compiler for cross-compilation, including compilation to another processor architecture (32-bit vs 64-bit).这就是您在使用编译器进行交叉编译时需要使用的内容,包括编译到另一个处理器架构(32 位与 64 位)。 The compiler itself will still be build for your host, but it will emit artifacts for another system.编译器本身仍将为您的主机构建,但它会为另一个系统发出工件。

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

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