本文主要是介绍macbook rust项目编译跨平台windows,linux,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
创建项目
cargo new test1
1, 编译windows exe包
rustup target add x86_64-pc-windows-gnu
brew install mingw-w64
cargo build --target i686-pc-windows-gnu
2. 编译ubuntu linux包
brew install FiloSottile/musl-cross/musl-cross
rustup target add x86_64-unknown-linux-gnu
ln -sf /usr/local/Cellar/musl-cross/0.9.9_2/libexec/bin/x86_64-linux-musl-gcc /usr/local/bin/x86_64-linux-gnu-gcc
cargo build --target x86_64-unknown-linux-gnu
3. 配置
vim .cargo/config
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"[target.i686-pc-windows-gnu]
linker = "i686-w64-mingw32-gcc"[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"
4. 如果出现相关异常或警告
export HOMEBREW_AUTO_UPDATE_SECS=86400
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_ENV_HINTS=1
echo ‘export HOMEBREW_AUTO_UPDATE_SECS=86400’ >> ~/.zshrc
echo ‘export HOMEBREW_NO_AUTO_UPDATE=1’ >> ~/.zshrc
echo ‘export HOMEBREW_NO_ENV_HINTS=1’ >> ~/.zshrc
source ~/.zshrc
这篇关于macbook rust项目编译跨平台windows,linux的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!