我有两个非常基本的rust-ink dapp合同:
Dapp 1
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
use dapp2;
#[ink::contract]
pub mod dapp1 {
use dapp2::dapp2::Dapp2;
#[ink(storage)]
pub struct Dapp1 {
dapp2_instance: Dapp2
}
impl Dapp1 {
/// Get existing `Dapp2` contract at `address`
#[ink(constructor)]
pub fn new(address: AccountId) -> Self {
let dapp2_instance: Dapp2 = ink_env::call::FromAccountId::from_account_id(address);
Self {
dapp2_instance
}
}
/// Calls the Dapp2 contract.
#[ink(message)]
pub fn dapp2_do_something(&mut self) -> u8 {
self.dapp2_instance.do_something()
}
}
}Dapp 1将dapp2指定为toml中的依赖项。
dapp2 = { version = "3.0.0-rc7", path ="../dapp2", default-features = false, features = ["ink-as-dependency"] }
Dapp 2
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
pub mod dapp2 {
#[ink(storage)]
pub struct Dapp2 {
pub what: u8,
}
impl Dapp2 {
#[ink(constructor)]
pub fn new() -> Self {
let what = 2.into();
Self {
what
}
}
#[ink(message)]
pub fn do_something(&mut self) -> u8 {
ink_env::debug_println!("{}", self.what);
self.what
}
}
}当我运行此构建时,dapp2编译,但是dapp1在
error[E0432]: unresolved import `dapp2`
--> /home/usr/dev/dapp-example/dapp1/lib.rs:4:5
|
4 | use dapp2;
| ^^^^^ no external crate `dapp2`甚至我的IDE在点击时也能找到dapp2,那么这个导入样式有什么问题呢?
我还看到了其他例子(1、2、3.),其中的合同只是简单地导入到模块中,但这似乎不适用于我。如果我这么做,我会得到:
7 | use dapp2::Dapp2Ref;
| ^^^^^ use of undeclared crate or module `dapp2`油墨设置为master分支。夜间生锈是最新的。版本是2021年。示例代码是论github
发布于 2021-12-18 09:13:17
问题是在crate-type文件中没有将rlib设置为rlib。
crate-type = [
# Used for normal contract Wasm blobs.
"cdylib",
# This was not set
"rlib"
]https://stackoverflow.com/questions/70398885
复制相似问题