rust x86_64-pc-windows-msvc 切换 x86_64-pc-windows-gnu
rustup target list
rustup target add i686-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
在Windows10 64位编译32位Rust程序
1、添加i686-pc-windows-msvc target
rustup target add i686-pc-windows-msvc
2、编译目标文件
cargo build --target=i686-pc-windows-msvc
如果编译成功,那么什么事也没了。 如果出现这样的错误:
error: linker `i686-pc-windows-msvc` not found
|
= note: 系统找不到指定的文件。 (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed with the Visual C++ option
error: aborting due to previous error
应该是找不到对应target的link.exe文件,需要在工程根目录下编写.cargo/config文件,加入以下内容:
[target.i686-pc-windows-msvc]
linker = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\Hostx64\\x86\\link.exe"
这里特别需要注意linker指向的link.exe文件,一定要指向x86的,跟你target相对应。
RUST如何在64位windows上编译32位的应用程序
1
2
rustup toolchain install stable-i686-pc-windows-msvc
rustup default stable-i686-pc-windows-msvc
1.在~/.cargo/config中加入以下行(注意第2行的意思是静态编译,这样编译出来的程序没有依赖,客户不用再在电脑上安装相应的依赖):
[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
2.在使用cargo进行编译
cargo build --release