rust - 为什么使用带有 #![no_std] 的 rand/rand_core 会导致“重复的语言项”?
问题描述
我正在尝试使用rand
or生成随机数rand_core
。根据文档,#![no_std]
可以使用default-features = false
. 因此,我尝试为两者都这样做,rand
并rand_core
查看其中一个是否有效。在这两种情况下我都会遇到相同的错误,所以我展示了我为rand_core
.
rand_core = {version = "0.5.1", default-features = false}
然后将其导入为:
use rand_core::RngCore;
但是,我收到以下错误(我没有编写这部分代码):
error[E0152]: found duplicate lang item `oom`
--> src/alloc.rs:116:1
|
116 | / fn alloc_error_handler(layout: Layout) -> ! {
117 | | panic!("allocation error: {:?}", layout)
118 | | }
| |_^
|
= note: the lang item is first defined in crate `std` (which `rand_core` depends on)
error[E0152]: found duplicate lang item `panic_impl`
--> src/panic.rs:21:1
|
21 | / fn panic(info: &PanicInfo) -> ! {
22 | | let mut host_stderr = ErStderr::default();
23 | |
24 | | writeln!(host_stderr, "{}", info).ok();
25 | |
26 | | unsafe {libc::exit(1); }
27 | | }
| |_^
|
= note: the lang item is first defined in crate `std` (which `rand_core` depends on)
error[E0152]: found duplicate lang item `eh_personality`
--> src/panic.rs:29:28
|
29 | #[lang = "eh_personality"] extern fn eh_personality() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `panic_unwind` (which `std` depends on)
这是一个最小的工作示例:https ://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7e748b901ea22742c878e8208d9c0691
我每晚使用。
这是我的Cargo.toml
。
[dependencies]
libc = "0.2"
cbindgen = "0.12.2"
rand_core = {version = "0.5.1", default-features=false}
[lib]
crate-type = ["staticlib"]
解决方案
我不知道为什么会这样,但是当我cbindgen
从依赖项列表中删除时,一切都会自动运行。
推荐阅读
- javascript - 如果字符串包含子字符串,则会出现问题
- windows - windows 10 检查是否启用了调试模式?
- go - 如何停止多个 goroutine
- mysql - Node.js 无法连接 mySQL
- kubernetes - nvalid value: 30004: 提供的端口已经分配
- python - 当我向旅行商问题添加更多顶点时,为什么我没有得到结果?
- node.js - 如何在服务器上停止/启动计时器
- javascript - 我不明白 javascript 替换是如何工作的
- java - 从mac卸载java
- c# - IdentityServer4 - AuthorizeAttribute 不验证 JWT 令牌/自定义用户存储