• substrate学习编写简单pallet的问题记录


    问题:

    添加自定义pallet到Substrate框架中,编译时遇到如下错误:

      --- stderr
         Compiling pallet-simple-pallet v4.0.0-dev (/Users/johnny/Documents/work/BlockChain/Substrate/substrate-node-template/pallets/simple-pallet)
      error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `panic_impl`.
        |
        = note: the lang item is first defined in crate `std` (which `pallet_simple_pallet` depends on)
        = note: first definition in `std` loaded from /Users/johnny/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libstd-f14dd22f8336e78a.rlib
        = note: second definition in `sp_io` loaded from /Users/johnny/Documents/work/BlockChain/Substrate/substrate-node-template/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-b3c1e7f3cef4f3ba.rmeta
    
      error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `oom`.
        |
        = note: the lang item is first defined in crate `std` (which `pallet_simple_pallet` depends on)
        = note: first definition in `std` loaded from /Users/johnny/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libstd-f14dd22f8336e78a.rlib
        = note: second definition in `sp_io` loaded from /Users/johnny/Documents/work/BlockChain/Substrate/substrate-node-template/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-b3c1e7f3cef4f3ba.rmeta
    
      error: could not compile `pallet-simple-pallet` due to 2 previous errors
    warning: build failed, waiting for other jobs to finish...
    error: build failed

    解决办法:

    在pallet的lib.rs第一行添加以下:

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

    此句的意思是:如果没有启动这个feature就启动no_std属性,这个属性会阻止std引入作用域。

    再重新编译。

    学习:Rust no-std 工程实践

  • 相关阅读:
    笔试材料收集(二)——用OPENGL搞个冒泡排序,原创_!
    cocos2dx andoroid切换后台后资源重载
    ipa命令行打包命令
    SceneManager
    ios上遇到过的问题集及解决方法(1)
    google inapp billing
    Unity Editor学习IHasCustomMenu
    cocos2dx如果更好地使用第三库
    cocos2dhtml环境布暑
    ios中,常用的一些调试命令
  • 原文地址:https://www.cnblogs.com/johnnyzhao/p/16214085.html
Copyright © 2020-2023  润新知