【问题标题】:multiple matching crates for `time` but there're no versions specified`time` 有多个匹配的 crate,但没有指定版本
【发布时间】:2014-11-24 03:02:16
【问题描述】:

我已经导入了一个创建 time 并且我正在使用另一个也使用(导入)time 的板条箱,因此我有一个错误:

/Users/alex/Documents/projects/rust/my_project/src/lib.rs:2:1: 2:19 error: multiple matching crates for `time`
/Users/alex/Documents/projects/rust/my_project/src/lib.rs:2 extern crate time;
                                                     ^~~~~~~~~~~~~~~~~~
note: candidates:
note: path: /usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtime-4e7c5e5c.dylib
note: path: /usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtime-4e7c5e5c.rlib
note: crate name: time
note: path: /Users/alex/Documents/projects/rust/my_project/target/deps/libtime-8fdb58a7632ec071.rlib
note: crate name: time
/Users/alex/Documents/projects/rust/my_project/src/lib.rs:2:1: 2:19 error: can't find crate for `time`
/Users/alex/Documents/projects/rust/my_project/src/lib.rs:2 extern crate time;
                                                     ^~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

如果我注释掉time,我也会收到一个错误,即找不到time。上面的错误甚至没有解释time 的版本是什么。我应该从磁盘中删除哪个?

【问题讨论】:

  • 你用的是cargo吗?

标签: rust


【解决方案1】:

crate 时间最近已移至外部存储库,但您目前仍将旧的 crate 与 rustc 捆绑在一起,因为它目前已被弃用。

因此,您有两个“libtime”板条箱,而 rustc 不知道哪一个。

当您使用 cargo 时,修复很简单:通过将 libtime 添加到您的 Cargo.toml 中,从而在依赖项中添加 libtime,cargo 会告诉 rusctc 它应该使用哪个 libtime。

[dependencies.time]
git = "https://github.com/rust-lang/time"

【讨论】:

  • 我应该从我的硬盘中删除一些吗?我用的是最新版的 Rust,怎么可能?
  • 旧的 libtime 仍然使用 rustc 发布。这样,仍在使用它的用户应该会收到弃用警告,而不是库丢失的神秘错误。然而,在像你这样的情况下,结果并不是那么好。
  • 我应该删除哪一个?
  • 如果你正确使用了cargo,你应该不需要删除任何。如果你真的想删除一个,它应该是与 rustc 捆绑的那个(你的情况是/usr/local/lib/... 中的那个)
  • 货物不能正常使用怎么办?
猜你喜欢
  • 2020-06-09
  • 2023-03-26
  • 1970-01-01
  • 2021-12-09
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多