微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未找到目标 thumbv7em-none-eabihf 的 sin()、cos()、log10()浮点数

如何解决未找到目标 thumbv7em-none-eabihf 的 sin()、cos()、log10()浮点数

我正在使用 Rust 1.51 和这个最小的箱子:

#![no_std]

fn main() {
    let a = 2.0.cos();
}

我用 cargo check --target thumbv7em-none-eabihf 构建它,编译器抱怨这条消息:no method named 'cos' found for type '{float}' in the current scopesin()log10() 相同。

我找到了 https://docs.rust-embedded.org/cortex-m-quickstart/cortex_m_quickstart/ 并且我希望目标 thumbv6m-none-eabithumbv7em-none-eabi 出现上述消息,但对于支持 FPU 的 thumbv7em-none-eabihf 不会。

我该如何解决这个问题?

解决方法

在 Rust 1.51(及更低版本)中,sincoslog10 等函数不是核心库 (core::) 的一部分,而只是标准库 ( std::),因此它们不可用。

一个实用的解决方案是使用 crate libm,它为 no_std 环境提供典型的数学函数。

#![no_std]

fn main() {
    let a = libm::cosf(2.0);
}

见:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。