M isaka E
「——天明明是这么的蓝 前途却是一片黑暗」

在win下使用cross交叉编译rust

1.下载Docker

  1. Docker 官网 安装 Docker Desktop
  2. 按照安装程序自动安装Docker和Wsl
  3. 启用wsl2
wsl --set-default-version 2
wsl --update

2.下载安装cross

cargo install cross

3.检查Docker

docker ps -a

4.尝试使用

cross build --release --target x86_64-unknown-linux-musl
此时可能会有报错:
toolchain 'stable-x86_64-unknown-linux-gnu' may not be able to run on this system
note: to build software for that platform, try `rustup target add x86_64-unknown-linux-gnu` instead
note: add the `--force-non-host` flag to install the toolchain anyway
Error: 
   0: couldn't install toolchain `stable-x86_64-unknown-linux-gnu`
   1: `rustup toolchain add stable-x86_64-unknown-linux-gnu --profile minimal` failed with exit code: 1

提示我们stable-x86_64-unknown-linux-gnu可能无法在此系统上运行

我们按照提示强制安装相关工具链

rustup toolchain add stable-x86_64-unknown-linux-gnu --profile minimal --force-non-host

安装成功后,再次运行:

cross build --release --target x86_64-unknown-linux-musl

即可交叉编译成功

posted @ 2026-01-31 02:35  MisakaE  阅读(4)  评论(0)    收藏  举报