error: native library `openssl` is being linked to by more than one version of the same package

error: native library `openssl` is being linked to by more than one version of the same package

我在尝试 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 和 Rust 版本:

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

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

文件:

不明白为什么这不能编译以及如何解决这个问题。 谢谢!

链接的工作方式,您只能链接一个本地库的单个版本,否则您最终会得到重复的符号。 Cargo 的 links manifest key 有助于防止您意外链接到同一组符号两次。

要解决它,您需要通读您的 Cargo.lock(这不是一种难以理解的文件格式)。找到将有问题的库作为依赖项的板条箱,并注意哪些有冲突的版本。

然后你必须手动解决你的依赖关系,以便他们的依赖关系使用相同版本的原生库。


在这种情况下,依赖链的重要方面是:

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

要修复它,请修改您的 Cargo.toml 以使用与 hyper 相同版本的 cookie。然后你会隐式得到相同版本的openssl。

老实说,这是目前 Rust 最粗糙的部分之一。至少 this 版本的 "multiple different versions of the same crate" 陌生性提供了直接的 Cargo 错误。