【问题标题】:Problems building the openssl crate with Cargo使用 Cargo 构建 openssl 板条箱的问题
【发布时间】:2019-01-28 18:05:10
【问题描述】:

每当我尝试编译时,我都会得到

  = note: /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libnative_tls-e4af7be01e0cc1c7.rlib(native_tls-e4af7be01e0cc1c7.native_tls.c3tq55qu-cgu.0.rcgu.o): in function `<openssl::stack::StackRef<T>>::len':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:171: undefined reference to `sk_num'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libnative_tls-e4af7be01e0cc1c7.rlib(native_tls-e4af7be01e0cc1c7.native_tls.c3tq55qu-cgu.0.rcgu.o): in function `<openssl::stack::StackRef<T>>::_get':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:242: undefined reference to `sk_value'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.11.rcgu.o): in function `openssl::ssl::compat::tls_method':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/ssl/mod.rs:2546: undefined reference to `SSLv23_method'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::Stack<T>>::new':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:40: undefined reference to `sk_new_null'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::Stack<T> as core::ops::drop::Drop>::drop':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:50: undefined reference to `sk_free'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::StackRef<T>>::pop':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:232: undefined reference to `sk_pop'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.4.rcgu.o): in function `openssl::version::number':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/version.rs:51: undefined reference to `SSLeay'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.6.rcgu.o): in function `openssl::x509::compat::X509_up_ref':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/x509/mod.rs:1172: undefined reference to `CRYPTO_add_lock'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl_sys-51d0c50f2e67767f.rlib(openssl_sys-51d0c50f2e67767f.openssl_sys.afwyjyem-cgu.9.rcgu.o): in function `openssl_sys::init::{{closure}}':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:150: undefined reference to `SSL_library_init'
          /usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:151: undefined reference to `SSL_load_error_strings'
          /usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:152: undefined reference to `OPENSSL_add_all_algorithms_noconf'
          /usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:154: undefined reference to `CRYPTO_num_locks'
          /usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:164: undefined reference to `CRYPTO_set_locking_callback'
          /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl_sys-51d0c50f2e67767f.rlib(openssl_sys-51d0c50f2e67767f.openssl_sys.afwyjyem-cgu.9.rcgu.o): in function `openssl_sys::init::set_id_callback':
          /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:139: undefined reference to `CRYPTO_set_id_callback'
          collect2: error: ld returned 1 exit status

Complete log

我同时安装了 OpenSSL 和 OpenSSL-1.0。我尝试过同时使用 Rust stable 和 nightly。我也尝试包含不同版本的 openssl crate,但我认为 Cargo 只是构建我认为 grpc 正在使用的 crate 版本。我在 Arch Linux 上。

【问题讨论】:

标签: linux rust archlinux rust-cargo


【解决方案1】:

您的项目正在使用不支持 OpenSSL 1.1.1 的 openssl 0.9.x(可能通过 tls-api-native-tls 0.1.x -> native-tls 0.1.x -> openssl 0.9.x)。我也在 Arch Linux 上,我必须将我的程序更新为 openssl 0.10 才能使用 OpenSSL 1.1.1。

在您的情况下,tls-api-native-tls 需要更新为依赖于使用 openssl 0.10.x(支持 OpenSSL 1.1.1)的 native-tls 0.2.xThere is an open issue about this.

如果这太复杂,您还可以使用各种环境变量来告诉openssl-sys 的构建脚本您想使用哪个 OpenSSL 安装。如果您更喜欢使用 OpenSSL 1.0.x,请在 shell 中输入以下命令:

$ cargo clean
$ OPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0 OPENSSL_LIB_DIR=/usr/lib/openssl-1.0 cargo build

(注意:以上路径可能特定于 Arch Linux。)

有关可用于配置openssl-sys 的环境变量的更多信息,请参阅Manual configuration

【讨论】:

  • 您拥有的命令与我用来构建的命令相同。我以为我在我的帖子中指定了这一点。当我刚刚运行cargo build 时,我得到 [this] (pastebin.com/XUitrh0D)。
  • 那么问题可能是链接器在 OpenSSL 1.0.x 库之前找到了 OpenSSL 1.1.x 库。在您的第一个构建日志中,我看到 -L native=/usr/lib/openssl-1.0 出现在 -L native=/usr/lib; 之后。这可以解释为什么。缺少的符号存在于 OpenSSL 1.0.x 中但不存在于 1.1.x 中,所以openssl-sys 认为它是针对 OpenSSL 1.0.x 构建的,但它实际上是与 OpenSSL 1.1.x 链接的。
猜你喜欢
  • 2022-11-28
  • 2014-09-01
  • 2022-06-15
  • 1970-01-01
  • 2012-08-05
  • 2020-06-13
  • 2018-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多