如何解决 RUST 交叉编译中的链接器错误

3

我正试图在Rust中实现针对树莓派的交叉编译。然而,在编译时遇到了链接错误:

error: linking with `cc` failed: exit status: 1

然而,为了解决这个问题,我必须下载新的链接器并不使用默认的链接器。 在此过程中,我使用以下命令检查我的树莓派系统的信息:

rustup show

得到以下结果:

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/akumar/.rustup

installed targets for active toolchain
--------------------------------------

arm-unknown-linux-gnueabihf
armv7-unknown-linux-gnueabihf
x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.64.0 (a55dd71d5 2022-09-19)

现在为了解决这个问题,我必须使用以下命令下载包:

sudo apt install gcc-armv7-unknown-linux-gnueabihf

但是运行命令后,我得到了以下错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package gcc-armv7-unknown-linux-gnueabihf

你在哪里编译?在主机还是目标设备上?如果你在主机上编译,可以尝试直接在你的树莓派上进行编译。 - al3x
1个回答

1
请尝试以下命令: sudo apt install gcc-arm-linux-gnueabihf 用于构建您的 Rust 项目,请输入: cargo build --target=armv7-unknown-linux-gnueabihf 请检查工具-cross:https://github.com/cross-rs/cross Cross 使用 Docker 进行构建,使库隔离。

1
谢谢!我发现对于工具链“gcc-armv7-unknown-linux-gnueabihf”,我们可以使用链接器“gcc-arm-linux-gnueabihf”。 - Ankit Kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接