Rust交叉编译问题(mac to linux) 2023

本文详细记录了作者在使用 Rust 进行从 MacOS 到 Linux 平台的交叉编译过程中遇到的种种问题,包括 OpenSSL 环境变量设置、linker 错误、musl 编译器的寻找和配置等,以及如何逐步解决这些问题的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Rust本身是支持跨平台编译的。看资料是只需要简单的跨平台编译命令就好了。

一、官方给出的资料是

rustup target add x86_64-unknown-linux-gnu
cargo build –release –target x86_64-unknown-linux-gnu

两条命令一出就 O 👌🏻了。然后到了我这里并非如此。问题是一波接着一波,像个解俄罗斯套娃一样。

二、找到 medium 上一个博主的回到。他是在 mul 和 gnu 的 Rust跨平台编译方式 上做了一个比较,然后取舍。

不过我都试了。并不能解决问题。

三、在 stackoverflow 上有一条相同的问题,是通过安装

brew install x86_64-unknown-linux-gnu

去尝试解决的,但是在我这里。一些莫名的报错,比如:

fatal: not in a git directory

Error: Command failed with exit 128: git

我明明实在 cargo new 创建的目录下的。这个不在 git 目录内,是莫名其妙,暂且不表。

四、后来找到github上的处理方式 macos-cross-toolchains

还是不行的

➜ chatgpt git:(main) ✗ brew install openssl@1.1
openssl@1.1 openssl@1.1 is already installed but outdated (so it will be upgraded).
==> Fetching dependencies for openssl@1.1 ==> Fetching dependencies for openssl@1.1: ca-certificates
==> Fetching ca-certificates
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/ca-certificates-2023-01-10.all.bottle.tar.gz
Already downloaded: /Users/c/Library/Caches/Homebrew/downloads/637587df586ffb04fbdb7243608f303e3e5f0da7c2d957ae45535261a60a6e7e–ca-certificates-2023-01-10.all.bottle.tar.gz
==> Fetching openssl@1.1
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1t.ventura.bottle.tar.gz
Already downloaded: /Users/c/Library/Caches/Homebrew/downloads/c32771c573f21242ce5120be535a7dac87a38f7a6d64fb9c61210e7156c30106– openssl@1.1-1.1.1t.ventura.bottle.tar.gz
==> Installing dependencies for <
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值