Rust,我的模块介绍突然遇到了一个问题

wgeznvg7  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(111)

这是以前从来没有出现过的问题,在我添加Excel功能后突然出现

use crate::common::offic::excel; // <<--
use clap::Parser;
use jni::objects::*;
use jni::JNIEnv;
use std::path::Path;  
use HspiceCompiler::hspice::spice; // <<-- 

#[derive(Parser, Debug)]
#[command(author, version, about)]
pub struct Args {
    #[clap(help = "Hspice file name")]
    pub file_name: String,
    #[clap(short, long)]
    pub output_path: String,
}

fn main() {
    let args = Args::parse();

    let spice_file = Path::new(&args.file_name);

    let output_path = Path::new(&args.output_path);

    loading(args);

    spice_file.try_exists().expect("Can't access hspice file");
    let mut reader = spice::Reader::new();
    let data_iter = reader.read(spice_file);
    reader.analysis_iter(data_iter);

    excel::write_to_excel(data_iter, output_path);
}
fn loading(args: Args) {
...
}

字符串
错误代码:

error[E0433]: failed to resolve: could not find `common` in the crate root
 --> src/bin/run.rs:1:12
  |
1 | use crate::common::offic::excel;
  |            ^^^^^^ could not find `common` in the crate root
error[E0433]: failed to resolve: use of undeclared type `HspiceCompiler`
 --> src/bin/run.rs:5:5
  |
5 | use HspiceCompiler::common::offic::excel;
  |     ^^^^^^^^^^^^^^ use of undeclared type `HspiceCompiler`


我的github -> run.rs:https://github.com/llllishuo/menghan_Hspice_Compiler/blob/main/src/bin/run.rs

qvk1mo1f

qvk1mo1f1#

crate引用crate的根模块,在本例中为 *src/bin/run.rs *。如果您想引用同一个包中的库crate,则需要通过包的名称来引用它。

use HspiceCompiler::common::offic::excel;

字符串
但是,您的包目前没有rust库,因为您的Cargo.toml只包含一个dynamic system library

[lib]
crate-type = ["cdylib"]


如果你想把这个库也用作rust库,你还应该包含lib

[lib]
crate-type = ["cdylib", "lib"]


这也会纠正你的第二个错误。

相关问题