【问题标题】:Rust Bare-Metal Cross-Compilation for AArch64: can't find crate for `core`AArch64 的 Rust 裸机交叉编译:找不到“core”的 crate
【发布时间】:2022-01-04 17:27:13
【问题描述】:

我正在尝试交叉编译示例 rust 代码作为 Linux (KDE-Neon) 上裸机 AArch64 的库。不幸的是,它不起作用。这是我的示例 rust 代码 (lib.rs):

#![no_std]

#[no_mangle]
pub extern "C" fn double_value (a : u32) -> u32
{
    a / 2
}

根据 [1],我首先安装了 rustup:

sudo snap install rustup --classic

之后,我跟着[2]跑了:

rustup toolchain list
rustup install stable
rustup default stable

然后我跟着[1]和[3]跑了:

rustup target add aarch64-unknown-none

但是当我之后尝试编译时,我不工作,无论是使用 rustc 还是使用 cargo:

rustc:

rustc --crate-type=lib lib.rs --target=aarch64-unknown-none
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-unknown-none` target may not be installed

error: aborting due to previous error

货物:

Cargo.toml:

[package]
name = "rust_baremetal_lib"
version = "0.1.0"
edition = "2018"

[lib]
name = "rust_baremetal_lib"
path = "src/lib.rs"
crate-type = ["staticlib"]

[dependencies]
cargo build --lib --target=aarch64-unknown-none
   Compiling rust_baremetal_lib v0.1.0 (/home/kilian/code/rust_link/rust_baremetal_lib)
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-unknown-none` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `rust_baremetal_lib`

To learn more, run the command again with --verbose.

在我看来 rustc 和 cargo 找不到核心库,尽管应该安装它,正如运行 rustc --print 时看到的那样:

rustc --print target-list|grep arch64-unknown-none
aarch64-unknown-none
aarch64-unknown-none-softfloat

我已经在互联网上查看过,但不幸的是没有找到任何线索。希望有人能帮我找到问题!

[1]https://rust-lang.github.io/rustup/cross-compilation.html

[2]No default toolchain configured after installing rustup

[3]https://doc.rust-lang.org/nightly/rustc/platform-support.html

【问题讨论】:

  • rustup component add rust-std-aarch64-unknown-none?
  • rustup component add rust-std-aarch64-unknown-none error: toolchain 'stable-x86_64-unknown-linux-gnu' does not contain component 'rust-std-aarch64-unknown-none' for target 'x86_64-unknown-linux-gnu' note: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html
  • 但是,当运行 rustup component list | grep aarch 时,它会输出:rust-std-aarch64-unknown-none (installed)

标签: rust cross-compiling rust-cargo arm64 bare-metal


【解决方案1】:

这个问题似乎是由损坏的 rust 安装引起的。我删除了所有可以通过 apt 和 snap 找到的与 rust 相关的软件包。之后我通过推荐的方式重新安装了 rust [1]。然后我又跑了:

rustup target add aarch64-unknown-none

后来 Cargo 抱怨说,我的示例代码中缺少“恐慌处理程序”,所以我在 [2] 之后插入了一个。我的示例代码现在如下所示:

#![no_std]

use core::{
    panic::PanicInfo,
};

#[no_mangle]
pub extern "C" fn double_value (a : u32) -> u32
{
    a * 2
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {
        continue;
    }
}

最后,我现在可以将这个示例交叉编译为 AArch64 裸机静态库:

cargo build --lib --target=aarch64-unknown-none

[1]https://www.rust-lang.org/tools/install

[2]https://interrupt.memfault.com/blog/zero-to-main-rust-1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多