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

Time:05-24

I'm on Windows 10 x64. I have Visual Studio 2019 installed, which allows me to compile C and C for both x32 and x64 without problems.

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.

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.

How can I fix this?

CodePudding user response:

This seems to be a misunderstanding on what is toolchain and what is 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).

When you install the toolchain, using the

rustup toolchain install toolchain-name

its name is defined as compiler_version-target_triple, e.g. stable-x86_64-pc-windows-msvc. The target triple here is the one which was used to build the compiler, i.e. 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 - e.g., if you need some code to use the nightly-only features, you'll install nigtly-*triple* alongside the 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). The compiler itself will still be build for your host, but it will emit artifacts for another system.

  • Related