2024-03-14 17:41 / 技术分享 Linux(Zorin OS)下跨平台编译 Rust 项目 ### 编译 Linux 平台 ``` rustup target add x86_64-unknown-linux-musl cargo build --release --target=x86_64-unknown-linux-musl ``` ### 编译 Windows 平台 ``` rustup target add x86_64-pc-windows-gnu cargo build --release --target=x86_64-pc-windows-gnu ``` ### 编译 macOS 平台 macOS Cross toolchain for Linux and *BSD:https://github.com/tpoechtrager/osxcross macOS SDK:https://github.com/alexey-lysiuk/macos-sdk 编译完成后结果分别在项目根目录`target`文件夹下的`x86_64-unknown-linux-musl`和`x86_64-pc-windows-gnu`文件夹下 #### 报错及解决方法 报错1:`error occurred: Failed to find tool. Is x86_64-w64-mingw32-gcc installed?` 解决方法:`apt install gcc-mingw-w64` 报错2:`error: failed to run custom build command for openssl-sys v0.x https://docs.rs/openssl/latest/openssl/` 解决方法:在 Cargo.toml 文件中 dependencies 项下添加如下代码 ``` # For Linux and macOS, we need the vendored ssl [target.'cfg(target_os = "linux")'.dependencies] openssl = { version = "0.10.57", features = ["vendored"] } [target.'cfg(target_os = "macos")'.dependencies] openssl = { version = "0.10.57", features = ["vendored"] } ```
发表评论 取消回复