gpt4 book ai didi

Rust 找不到 crate

转载 作者:行者123 更新时间:2023-12-03 11:39:59 41 4
gpt4 key购买 nike

我正在尝试在 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/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com