在 macos 中为 linux 构建 Rust 时出错 - Openssl

问题描述 投票:0回答:4

尝试从 mac 为 linux 编译会引发此错误,我从 brew 安装了 opensslpkg-config

在文件 ~/.cargo/config 中我有这个配置。

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

错误:

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

Caused by:
  process didn't exit successfully: `/Users/Proyect/cvm/target/release/build/openssl-sys-66182f9fe15cdddc/build-script-main` (exit status: 101)
  run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit status: 1\nerror: could not find system library 'openssl' required by the 'openssl-sys' crate\n\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'openssl' found\n"

  --- 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-apple-darwin
  $TARGET = x86_64-unknown-linux-gnu
  openssl-sys = 0.9.72

  ', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.72/build/find_normal.rs:180:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
rust build openssl rust-cargo pkg-config
4个回答
7
投票

报错信息包含三种可能的解决方案:

首先确保它确实已安装,包括用于开发(如果你想针对 openssl 编译代码,这是你需要的):

确保您还安装了 openssl 的开发包。 例如,Ubuntu 上的

libssl-dev
或 Fedora 上的
openssl-devel

如果真的已经安装了,那就找不到了。这可以通过将包含 `openssl.pc' 的目录添加到 PKG_CONFIG_PATH 环境变量来解决:

在 pkg-config 搜索路径中找不到包 openssl。也许 您应该将包含“openssl.pc”的目录添加到 PKG_CONFIG_PATH 环境变量。

或者通过将

OPENSSL_DIR
设置为指向系统上 openssl 代码的位置:

找不到OpenSSL安装目录,这

-sys
如果没有这些知识,板条箱就无法继续。如果安装了 OpenSSL 这个箱子找不到它,你可以设置
OPENSSL_DIR
编译过程的环境变量。


0
投票

经过多次尝试,我发现了这个 script 从 mac 为 linux 编译。

你只需要将它复制到项目的根文件夹并运行它。


0
投票

我不得不在 Mac 上设置/导出这些 openssl(brew 安装)目录,试图编译 AWS Lambda Rust 函数:

export OPENSSL_LIB_DIR=/usr/local/opt/openssl/bin/openssl export OPENSSL_DIR=/usr/local/opt/openssl/bin/openssl export OPENSSL_LIB_DIR=/usr/local/opt/openssl/lib 

这是我收到的错误消息的一部分,希望能帮助到 2023 年仍在使用 Google 的编码人员:

cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset

-3
投票

尝试添加

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

到你的 Cargo.toml

© www.soinside.com 2019 - 2024. All rights reserved.