我正在尝试将一个示例rust代码交叉编译为Linux(KDE-Neon(上的裸机AArch64库。不幸的是,它不起作用。这是我的示例铁锈代码(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时所看到的那样--打印:
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] 安装锈蚀后未配置默认工具链
[3]https://doc.rust-lang.org/nightly/rustc/platform-support.html
这个问题似乎是由锈蚀的安装损坏引起的。我通过apt和snap删除了所有与铁锈有关的包裹。之后,我通过推荐的方式[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