簡體   English   中英

Rust AArch64 的裸機交叉編譯:找不到“核心”的板條箱

[英]Rust Bare-Metal Cross-Compilation for AArch64: can't find crate for `core`

我正在嘗試交叉編譯示例 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 還是使用貨物:

銹跡:

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

貨物:

貨物.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] 安裝 rustup 后沒有配置默認工具鏈

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

該問題似乎是由損壞的 rust 安裝引起的。 我刪除了所有與 rust 相關的軟件包,我可以通過 apt 和 snap 找到這些軟件包。 之后我通過推薦的方式 [1] 重新安裝了 rust。 然后我又跑了:

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 裸機 static 庫:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM