搭建 RUST 交叉编译环境

在嵌入式 `Linux` 上运行 `RUST`

  • [在嵌入式 `Linux` 上运行 `RUST`](#在嵌入式 Linux 上运行 RUST)
    • [构造交叉编译的 `RUST` 环境](#构造交叉编译的 RUST 环境)
    • 编译代码
    • 其他
  • 参考文档

在嵌入式 Linux 上运行 RUST

最近在开发 zynq 相关的产品,想使用 rust 来开发应用程序;所以研究了一下如何在 pc 上进行 rust 的交叉编译。

本人用的是 zynq 的 7035 芯片,里面包含两个 cortex-A7 的处理器。

shell 复制代码
$ cat /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 383.33
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x3
CPU part	: 0xc09
CPU revision	: 0

processor	: 1
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 383.33
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x3
CPU part	: 0xc09
CPU revision	: 0

Hardware	: Xilinx Zynq Platform
Revision	: 0003
Serial		: 0000000000000000

构造交叉编译的 RUST 环境

  • 查看 rust 支持的 target
shell 复制代码
rustup target list
  • 安装需要的 target
shell 复制代码
rustup target add armv7-unknown-linux-gnueabihf
  • 编写配置文件

~/.cargo/config.toml 中添加配置信息

shell 复制代码
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

可以在此设置使用哪个编译器。

我设置为 zynqarm-xilinx-linux-gnueabi-gcc 后提示连接失败,应该是还需要设置其他的,暂时没有研究。

  • 安装编译器
shell 复制代码
sudo apt-get install -y libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf

编译代码

shell 复制代码
cargo build --target armv7-unknown-linux-gnueabihf

其他

rust 代码虽然是静态编译,但是会使用系统的 libc 动态库。

在我将代码复制到嵌入式系统上运行后,提示找不到 libgcc_s.so.1 动态库

shell 复制代码
./hello: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory

zynq 提供的资料中,找到该动态库,并复制到嵌入式系统的 /lib 文件夹下,就可以正常运行了。

参考文档

《Rust交叉编译armv7环境配置》

相关推荐
qq. 280403398441 分钟前
js 原型链分析
开发语言·javascript·ecmascript
鹿衔`1 小时前
Flask入门
后端·python·flask
Elnaij1 小时前
从C++开始的编程生活(13)——list和浅谈stack、queue
开发语言·c++
q***07143 小时前
Spring Boot 多数据源解决方案:dynamic-datasource-spring-boot-starter 的奥秘(上)
java·spring boot·后端
q***49863 小时前
Spring Boot 3.4 正式发布,结构化日志!
java·spring boot·后端
一晌小贪欢5 小时前
【Python数据分析】数据分析与可视化
开发语言·python·数据分析·数据可视化·数据清洗
alwaysrun6 小时前
Rust中元组详解
rust·元组·tuple·解构
ftpeak6 小时前
Tauri开发手记——1.开发环境
rust·tauri
草莓火锅7 小时前
用c++使输入的数字各个位上数字反转得到一个新数
开发语言·c++·算法
j_xxx404_7 小时前
C++ STL:阅读list源码|list类模拟|优化构造|优化const迭代器|优化迭代器模板|附源码
开发语言·c++