如何解决 Substrate `std' 中的重复 lang 项('myexternalcrate' 所依赖的):'panic_impl' 与 sr-io 冲突

问题描述 投票:0回答:3

我在 Substrate 1.0 运行时模块中使用 extern crate(基于

node-template
),它给出了

的编译错误
duplicate lang item in crate 'std' (which 'myexternalcrate' depends on): 'panic_impl'.

= note: first defined in crate `sr_io` (which `node_template_runtime` depends on).

如果我正确理解了该消息,那么如果开发人员想要包含依赖于已在

std
中实现的
sr-io
功能的外部包,那么我认为这可能是一个常见问题,但我不确定这是否正确。

我在here看到了这个问题,它似乎已在

sr-io
中修复,但这似乎不是这里的原因。

他们有另一种方法来解决这个问题吗?

编辑:添加对

Cargo.toml
的更改 我们正在尝试拉入名为 nacl 的板条箱

[dependencies]
nacl = {version = "0.3.0", default-features = false}

已添加

lib.rs

extern crate nacl;

在运行时模块中

use nacl::public_box::*;
substrate
3个回答
6
投票

您尝试使用的 crate (

rust-nacl
) 不支持
no_std
,因此无法在 Substrate 运行时环境中使用。

选项有:

  • 找到另一个支持
    no_std
    并具有类似功能的板条箱:https://crates.io/keywords/no_std
  • 更新/编写一个板条箱来支持
    no_std
    (根据板条箱,这可能不会那么糟糕)。

0
投票

为了澄清肖恩·塔布里兹(Shawn Tabrizi)上面的回答...... 要使用另一个支持 no_std 的板条箱:

imported_crate = { git = "...", default-features = false, branch = "..." }

或者写一个箱子来支持 no_std :

#![cfg_attr(not(feature = "std"), no_std)]

有关 no_std 的更多信息:https://substrate.stackexchange.com/questions/1307/how-to-resolve-duplicate-lang-item-error


0
投票

在no_std环境下用

node_template_runtime
编译
std
时可能会出现这种错误。因此,在上面的示例中,您应该检查是否为
node_template_runtime
启用了 std,而不是启用它。

© www.soinside.com 2019 - 2024. All rights reserved.