You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rust交叉编译树莓派遇链接错误,安装指定GCC包失败求助

解决Rust交叉编译到树莓派的链接错误及链接器安装问题

问题分析

交叉编译到树莓派(armv7架构)时出现的链接错误,是因为Rust默认使用系统cc链接器无法适配arm架构目标。你尝试安装的链接器包名称有误,Debian/Ubuntu系发行版中armv7交叉编译gcc的包名并非gcc-armv7-unknown-linux-gnueabihf。

解决方案

1. 安装正确的交叉编译链接器

先更新软件源,再安装适配armv7架构的交叉编译工具链:

sudo apt update && sudo apt install gcc-arm-linux-gnueabihf

该包包含树莓派所需的arm-linux-gnueabihf-gcc链接器。

2. 配置Rust使用指定链接器

在Rust项目根目录(或用户主目录下的.cargo文件夹)创建/编辑config.toml文件,添加目标对应的链接器配置:

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

如果需要适配arm-unknown-linux-gnueabihf目标,可追加:

[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

3. 重新编译项目

指定目标架构编译项目:

cargo build --target armv7-unknown-linux-gnueabihf

内容的提问来源于stack exchange,提问作者Ankit Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 11:20:36