rust 使用中的笔记

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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值