gpt4 book ai didi

rust - 导入我自己的标准库时如何避免导入冲突?

转载 作者:行者123 更新时间:2023-11-29 07:58:36 26 4
gpt4 key购买 nike

我正在尝试导入我自己的 std 库,但是当我使用 crate 依赖项进行编译时,我遇到了这个问题:

error: duplicate lang item in crate `std`: `f32`.
|
= note: first defined in crate `my_std`.

error: duplicate lang item in crate `std`: `f64`.
|
= note: first defined in crate `my_std`.

error: duplicate lang item in crate `std`: `panic_fmt`.
|
= note: first defined in crate `my_std`.

我试图通过编写 extern crate my_std as std 来覆盖库

什么是解决这个问题的简单方法 - 而不是为所有依赖项修改它?

最佳答案

您可以使用 #![no_std] 在没有 Rust 标准库的情况下编译您的代码 crate 根中的属性。请注意,使用可执行文件(而不是库)执行此操作有一些注意事项,您需要 manually include libc对于二进制文件。

关于rust - 导入我自己的标准库时如何避免导入冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com