在编译ARM时,OpenSSL无法编译,其他情况下可以正常工作。

3

最近我一直在为ARM编译一个Rust项目。它可以完美地编译x86,但是每当我切换到ARM目标时,它就无法找到Openssl安装,我已经安装并使用了pkg-config,所以不是那个错误。也不确定如何成功设置OPENSSL_DIR变量或在哪里找到安装文件。完整的错误信息如下:

error: failed to run custom build command for `openssl-sys v0.9.61`

Caused by:
  process didn't exit successfully: `/home/bob/yagna/blueberry/debug/build/openssl-sys-aae22c7790b14724/build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_LIB_DIR
  ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_INCLUDE_DIR
  ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_DIR
  ARMV7_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "pkg-config has not been configured to support cross-compilation.\n\n                Install a sysroot for the target platform and configure it via\n                PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\n                cross-compiling wrapper for pkg-config and set it via\n                PKG_CONFIG environment variable."

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = armv7-unknown-linux-gnueabihf
  openssl-sys = 0.9.61

  ', /home/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.61/build/find_normal.rs:174:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

.cargo配置文件如下:

[build]
target-dir="/home/bob/yagna/blueberry"
target="armv7-unknown-linux-gnueabihf"
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

我不知道该怎么做,我的Ubuntu已经安装并更新了libssl-dev,目标是使用rustup和sudo apt-get进行添加和安装。不确定如何解决这个问题。


1
你需要为目标架构安装libssl-dev - undefined
好的,对于将来遇到这个问题的人来说,将其作为供应商处理是有效的。 - undefined
1
我绝对不会推荐使用 OpenSSL 作为供应商,因为它经常有安全更新,除非你非常小心地更新它,否则你的代码将存在安全漏洞。 - undefined
你能解释一下你是怎么卖掉它的吗,@Frustrated?谢谢! - undefined
@CorneliusRoemer 是的,不过我建议你尝试其他解决方案,否则你的代码可能很快就会变得容易受到攻击。在你的Cargo.toml文件中添加openssl = { version = "0.10", features = ["vendored"] }就可以实现这个功能。 - undefined
1个回答

5

如果你要为 armhf 编译使用 OpenSSL 的东西,那么你需要安装适用于该架构的 libssl-dev 包。这将包括通过 dpkg --add-architecture armhf 建立 dpkg 并进行 apt-get updateapt-get install libssl-dev:armhf

请注意,可能无法同时安装多个版本的 libssl-dev,并且以不删除许多软件包的方式解决依赖关系可能会很棘手。Debian 风格的多架构非常强大,但有时会有些琐碎。

绝不能捆绑 OpenSSL,因为它经常发布安全更新。同样,静态链接 OpenSSL 也是一个坏主意。如果你将其捆绑或静态链接,除非你非常小心地保持其最新状态,否则你的代码将包含安全漏洞。


我尝试做这个,但是出现了以下错误:E: 无法找到软件包 libssl-dev:armhf我该如何修复它? - undefined
很遗憾,这个评论空间太小了,无法回答你的问题,因为我们需要看到你所见到的完整错误信息以及你所采取的步骤来解决问题。你最好在Super User上提一个新问题。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接