11

When running cargo build:

error: multiple matching crates for `url`

It then lists the candidates:

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

... and then aborts because it cannot decide which one.

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

How to work around this, or fix this problem?


NOTE:

This issue and this commit appear to be related to the problem, from the comments:

+//! 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.

Installation specifics:

$ 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)

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"

(copied from http://nickel.rs/getting-started.html and added one extra dependency)

The full error that I get is this:

   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.
bojangle
  • 888
  • 1
  • 8
  • 14
  • What is your `Cargo.toml`? – huon Aug 01 '14 at 08:22
  • @dbaupp Added the toml file to the question. – bojangle Aug 04 '14 at 00:55
  • 2
    That happens because the Nickel depends on the `github.com/servo/rust-url` while the Postgres uses the stock old `url`, AFAIK. Might be a Cargo problem in that it doesn't treat the dependencies on a per unit basis. – ArtemGr Sep 29 '14 at 07:06

1 Answers1

1

Now (today's version of Cargo) it also gives this error during fetching packages:

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

All you can do in both cases it's repoint one of your dependencies to the same transitive dependency by changing their Cargo.toml right inside the cloned rustlib or nickel (or curl-rust in openssl-sys case) and repoint your Cargo.toml to the changed one: http://doc.crates.io/build-script.html#overriding-build-scripts, so it's just one line inside your .cargo/config:

 paths = ["/path/to/overridden/dependency"]

And something like that in /path/to/overridden/dependency/Cargo.toml:

 [dependencies]
 transitive-dependency-name = "choosed-version"

You could point it to the git here.

More about multi-linkage issue: https://github.com/rust-lang/cargo/issues/886

dk14
  • 22,206
  • 4
  • 51
  • 88