在win下使用cross交叉编译rust
1.下载Docker
- 从 Docker 官网 安装 Docker Desktop
- 按照安装程序自动安装Docker和Wsl
- 启用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
即可交叉编译成功

浙公网安备 33010602011771号