如何解决货物中"多包装箱"的问题?

boj*_*gle 10 rust rust-crates rust-cargo

运行时cargo build:

error: multiple matching crates for `url`
Run Code Online (Sandbox Code Playgroud)

然后列出候选人:

  • ./target/deps/liburl-11a95471847b9e04.rlib
  • /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liburl-4e7c5e5c.{so,rlib}

......然后中止,因为它无法决定哪一个.

src/http/lib.rs:18:1: 18:18 error: can't find crate for `url`
src/http/lib.rs:18 extern crate url;
                   ^~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题,或解决这个问题?


注意:

问题 和此提交 似乎与问题相关,来自评论:

+//! rust-url’s crate is also named `url`.
+//! Cargo will automatically resolve the name conflict,
+//! but that means that you can not also use the old `url` in the same crate.
Run Code Online (Sandbox Code Playgroud)

安装细节:

$ rustc -v
rustc 0.12.0-pre-nightly (7a25cf3f3 2014-07-30 17:06:18 +0000)
$ cargo -V
0.0.1-pre-nightly (4a69ffa 2014-07-29 21:30:40 +0000)
Run Code Online (Sandbox Code Playgroud)

Cargo.toml:

[package]

name = "nickel-demo"
version = "0.1.0"
authors = [ "your-name@gmail.com" ]

[[bin]]

name = "nickel-demo"
path = "src/main.rs"

[dependencies.nickel]

git = "https://github.com/nickel-org/nickel.rs.git"

[dependencies.rust-postgres]

git = "https://github.com/sfackler/rust-postgres.git"
Run Code Online (Sandbox Code Playgroud)

(从http://nickel.rs/getting-started.html复制并添加了一个额外的依赖项)

我得到的完整错误是这样的:

   Compiling rust-postgres v0.0.0 (https://github.com/sfackler/rust-postgres.git#7d842441)
Build failed, waiting for other jobs to finish...
Could not compile `rust-postgres`.

--- stderr
src/lib.rs:70:1: 70:18 error: multiple matching crates for `url`
src/lib.rs:70 extern crate url;
              ^~~~~~~~~~~~~~~~~
note: candidates:
note: path: /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liburl-4e7c5e5c.so
note: path: /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liburl-4e7c5e5c.rlib
note: crate name: url
note: path: /home/bojangle/k/nickel-demo/target/deps/liburl-11a95471847b9e04.rlib
note: crate name: url
src/lib.rs:70:1: 70:18 error: can't find crate for `url`
src/lib.rs:70 extern crate url;
              ^~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors


To learn more, run the command again with --verbose.
Run Code Online (Sandbox Code Playgroud)

dk1*_*k14 1

现在(今天的 Cargo 版本)在获取包时也会出现此错误:

native library `openssl` is being linked to by more than one package, and can only be linked to by one package

  openssl-sys v0.2.13 (https://github.com/sfackler/rust-openssl.git#2f5d1e57)
  openssl-sys v0.2.15
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,您所能做的就是通过更改Cargo.toml克隆的 rustlib 或 Nick (或 openssl-sys 中的curl-rust)内的右侧依赖项,将您的依赖项之一重新指向相同的传递依赖项,并将您的依赖项重新Cargo.toml指向更改后的依赖项:http:// /doc.crates.io/build-script.html#overriding-build-scripts,所以它只是 .cargo/config 中的一行:

 paths = ["/path/to/overridden/dependency"]
Run Code Online (Sandbox Code Playgroud)

/path/to/overridden/dependency/Cargo.toml 中类似的内容:

 [dependencies]
 transitive-dependency-name = "choosed-version"
Run Code Online (Sandbox Code Playgroud)

你可以把它指向这里的 git 。

有关多联动问题的更多信息:https://github.com/rust-lang/cargo/issues/886