错误[E0463]:为 Thumbv8m 构建时,无法从导入的板条箱中找到"分配"错误的板条箱。



我正在尝试使用一个在嵌入式应用程序中使用ffcrate的库,但正如标题所说,即使我在Cargo.toml中启用了alloc功能标志,我也会从导入库中使用的crate中获得错误。

我还仔细检查了我添加的特定目标是thumbv8.main-none-eabi

下面是一个简单的复制代码:

文件结构:

embd-app      <-- embed application, import some-crate
|--.cargo/config
|--Cargo.toml
|--src
|--main.rs
some-crate    <-- a crate uses ff crate
|--Cargo.toml
|--src
|--lib.rs

embd-app/.cargo/配置:

[build]
target = "thumbv8m.main-none-eabi"
[unstable]
build-std = ["core"]

embd-app/Cargo.toml

[dependencies]
some-crate = { path = "../some-crate", default-features = false , features = ["alloc"] }

embd-app/src/main.rs

#![no_std]
#![no_main]
/// some code

some-crate/Cargo.toml

[package]
name = "some-crate"
version = "0.1.0"
edition = "2021"
[dependencies]
ff = { version="0.13.0", default-features = false }
[features]
default = ["std"]
alloc = ["ff/alloc"]
std = ["alloc"]

some-crate/src/lib.rs

// The code is minimized just to generate an error
#![no_std]
#[cfg(feature = "alloc")]
extern crate alloc;
use alloc::{vec, vec::Vec};
pub fn foo() -> Vec<u8> {
vec![1, 2]
}

目标补充道:

$ rustup target list | grep installed
aarch64-apple-darwin (installed)
thumbv8m.main-none-eabi (installed)

编译错误信息:

error[E0463]: can't find crate for `alloc`
--> /Users/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/ff-0.13.0/src/lib.rs:10:1
|
10 | extern crate alloc;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
For more information about this error, try `rustc --explain E0463`.
error: could not compile `ff` due to previous error

我没有预料到这样的错误消息,因为我指定了features = ["alloc"]标志,有什么是错误的?

正如@jthulhu和@chaim-friedman在评论中提到的,我可以通过添加build-std = ["core", "alloc"]来解决这个问题。

最新更新