Rust 找不到 crate

标签 rust rust-crates

我正在尝试在 Rust 中创建一个模块,然后从不同的文件中使用它。这是我的文件结构:

matthias@X1:~/projects/bitter-oyster$ tree
.
├── Cargo.lock
├── Cargo.toml
├── Readme.md
├── src
│   ├── liblib.rlib
│   ├── lib.rs
│   ├── main.rs
│   ├── main.rs~
│   └── plot
│       ├── line.rs
│       └── mod.rs
└── target
    └── debug
        ├── bitter_oyster.d
        ├── build
        ├── deps
        ├── examples
        ├── libbitter_oyster.rlib
        └── native

8 directories, 11 files

这是 Cargo.toml:
[package]
name = "bitter-oyster"
version = "0.1.0"
authors = ["matthias"]

[dependencies]

这是 main.rs:
extern crate plot;

fn main() {
    println!("----");
    plot::line::test();
}

这是 lib.rs:
mod plot;

这是情节/mod.rs
mod line;

这是 plot/line.rs
pub fn test(){
    println!("Here line");
}

当我尝试使用以下命令编译我的程序时:cargo run我得到:
   Compiling bitter-oyster v0.1.0 (file:///home/matthias/projects/bitter-oyster)
/home/matthias/projects/bitter-oyster/src/main.rs:1:1: 1:19 error: can't find crate for `plot` [E0463]
/home/matthias/projects/bitter-oyster/src/main.rs:1 extern crate plot;

如何编译我的程序?据我从在线文档中可以看出,这应该可以工作,但事实并非如此。

最佳答案

如果您看到此错误:

error[E0463]: can't find crate for `PACKAGE`
  |
1 | extern crate PACKAGE;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

可能是您没有将所需的 crate 添加到 Cargo.toml 中的依赖项列表中。 :
[dependencies]
PACKAGE = "1.2.3"

specifying dependencies in the Cargo docs .

关于Rust 找不到 crate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59364248/

相关文章:

rust - 是否使用rust 格式!宏提供用户指定的填充字符

rust - 链接到二进制箱子

rust - 如何处理标有木马的木箱?

rust - crypto::hmac::Hmac::new 中的参数类型不匹配

rust - 如何解决为什么 cargo/rustc 链接在 rust 标准库符号中,即使使用了 no_std?

rust - 如何在不使用匹配的情况下从元组设置结构成员?

module - 是否有可能有一个模块,部分可以在 crate 外部访问,部分只能在 crate 内部访问?

rust - 如何清除 cargo 缓存?

rust - 使用 main.rs 文件从本地 crate 导入时未解析的导入

rust - 通过索引访问借用字符串中的字符