11

I'm facing this problem when I try to cargo build:

error: native library openssl is being linked to by more than one version of the same package, but it can only be linked once; try updating or pinning your dependencies to ensure that this package only shows up once

openssl-sys v0.6.7

openssl-sys v0.7.13

Cargo and Rust versions:

$ cargo --version
cargo 0.11.0-nightly (3ff108a 2016-05-24)

$ rustc --version
rustc 1.11.0-nightly (7746a334d 2016-05-28)

Files:

can't get why this doesn't compile and how to solve this problem. Thank you!

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
mgul
  • 742
  • 8
  • 27

1 Answers1

10

The way that linking works, you can only have a single version of a native library linked, otherwise you end up with duplicate symbols. Cargo's links manifest key helps prevent you from accidentally linking to the same set of symbols twice.

To solve it, you need to read through your Cargo.lock (it's not a difficult file format to understand). Find the crates that have the offending library as a dependency and note which ones have conflicting versions.

Then you have to manually resolve your dependencies so that their dependencies use the same version of the native library.


In this case, the important aspects of the dependency chain are:

server (0.0.1) => cookie (0.2.4) => openssl (0.7.13)
               => hyper (0.6.16) => cookie (0.1.21) => openssl (0.6.7)

To fix it, modify your Cargo.toml to use the same version of cookie as hyper. Then you will implicitly get the same version of openssl.

To be honest, this is one of the roughest parts of Rust at the moment. At least this version of the "multiple different versions of the same crate" strangeness provides a straight-forward Cargo error.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • 3
    I just submitted a [pull request](https://github.com/kbknapp/cargo-graph/pull/29) to cargo-graph to help visualize this kind of dependency issues. – Francis Gagné May 30 '16 at 04:53
  • Thank you, I did this with all my dependencies to be "aligned" in the same version. It was a lot of dark work, hope they'll do something about it. – mgul Jun 07 '16 at 20:38
  • What do I do if I have a library that absolutely requires an up-to-date openssl? I'm trying to use hyper and git2 at the same time and can't build it now due to hyper requiring an old version of openssl. The dependency for hyper is optional, though. Is there some way to force cargo to use the version required by git2 and treat hyper as if no openssl was present? – Machisuji Nov 26 '16 at 15:18
  • @Machisuji that would probably be better asked as a separate question. However, you can use Cargo *features* to disable the OpenSSL dependency of Hyper, if you don't need it. – Shepmaster Nov 26 '16 at 15:20
  • Thanks! I created a separate question: http://stackoverflow.com/questions/40824435/using-both-git2-and-hyper-openssl-linked-more-than-once – Machisuji Nov 27 '16 at 00:02