4

I want to use several MD5 implementations in the same Rust program.

Two of them both want to be named "md5", which is causing an error from the compiler:

error[E0465]: multiple rlib candidates for `md5` found
  --> md5s/src/lib.rs:10:1
   |
10 | extern crate md5;
   | ^^^^^^^^^^^^^^^^^
   |
note: candidate #1: /home/dstromberg/src/home-svn/md5s/trunk/target/debug/deps/libmd5-256ebb56f51dbbc0.rlib
  --> md5s/src/lib.rs:10:1
   |
10 | extern crate md5;
   | ^^^^^^^^^^^^^^^^^
note: candidate #2: /home/dstromberg/src/home-svn/md5s/trunk/target/debug/deps/libmd5-56cccd41ff35cdb0.rlib
  --> md5s/src/lib.rs:10:1
   |
10 | extern crate md5;
   | ^^^^^^^^^^^^^^^^^

error[E0463]: can't find crate for `md5`
  --> md5s/src/lib.rs:10:1
   |
10 | extern crate md5;
   | ^^^^^^^^^^^^^^^^^ can't find crate

Is there a way of renaming one or both of them without subverting cargo?

The specific crates are:

I have 2 Cargo.toml's:

$ grep -n . $(find . -name Cargo.toml -print)
below cmd output started 2018 Wed Nov 14 06:03:48 PM PST
./md5s/Cargo.toml:1:[package]
./md5s/Cargo.toml:2:name = "md5s"
./md5s/Cargo.toml:3:version = "0.1.0"
./md5s/Cargo.toml:4:authors = ["xxxxxxxx@gmail.com"]
./md5s/Cargo.toml:6:[dependencies]
./md5s/Cargo.toml:7:rust-crypto = "^0.2"
./md5s/Cargo.toml:8:md5 = "^0.5"
./md5s/Cargo.toml:9:# md-5 = "^0.8.0"
./Cargo.toml:1:# Cargo structure based on https://stackoverflow.com/questions/26946646/rust-package-with-both-a-library-and-a-binary
./Cargo.toml:2:[package]
./Cargo.toml:3:name = "compare-md5s"
./Cargo.toml:4:version = "0.1.0"
./Cargo.toml:5:authors = ["Dan Stromberg <xxxxxxxx@gmail.com>"]
./Cargo.toml:7:[workspace]
./Cargo.toml:9:[dependencies]
./Cargo.toml:10:md5s = { path = "md5s" }
./Cargo.toml:11:rust-crypto = "^0.2"
./Cargo.toml:12:md5 = "^0.5"
./Cargo.toml:13:# md-5 = "^0.8.0"

The project builds if I leave the 2 md-5's commented out, and fails with the error above if I uncomment them.

In md5s/src/lib.rs, I have:

extern crate md5;
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
dstromberg
  • 6,954
  • 1
  • 26
  • 27
  • 1
    Please add your Cargo.toml relevant section and the `extern crate` lines – Boiethios Nov 15 '18 at 01:58
  • I guess that's just an issue of crate alias. Does it work if you do `extern crate md5 as md5_other;`? – Boiethios Nov 15 '18 at 02:38
  • "crate as" gives an almost identical error, except the last bit is "error[E0463]: can't find crate for `md5_other`". – dstromberg Nov 15 '18 at 02:50
  • Yes, it's a duplicate. I switched to cargo +nightly, added cargo-features = ["rename-dependency"], and then "md_5 = { package = "md-5", version = "^0.8.0" }" worked. – dstromberg Nov 15 '18 at 14:42
  • Unfortunately, this does not exists in stable Rust. I hope for you it will be stabilized soon! As a workaround, you can maybe create your own crate with a different name and reexport the whole md5 crate – Boiethios Nov 15 '18 at 15:03

0 Answers0