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

发布于 2025-01-10 21:23:21 字数 1975 浏览 0 评论 0原文

尝试从 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

Trying to compile for linux from a mac throws this error, I have openssl and pkg-config installed from brew.

And in the file ~/.cargo/config I have this configuration.

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

Error:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼前雾蒙蒙 2025-01-17 21:23:21

该错误消息包含三种可能的解决方案:

首先确保它确实已安装,包括用于开发(如果您想针对 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
如果没有这些知识,crate 就无法继续。如果安装了 OpenSSL
并且此箱子无法找到它,您可以设置OPENSSL_DIR
编译过程的环境变量。

The error message contains three possible solutions:

First make sure it is really installed including for development (which is what you need if you want to compile code against openssl):

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

If it is already really installed, then it could not be found. This can be fixed by adding the directory containing `openssl.pc' to the PKG_CONFIG_PATH environment variable:

Package openssl was not found in the pkg-config search path. Perhaps
you should add the directory containing `openssl.pc' to the
PKG_CONFIG_PATH environment variable.

Or by setting the OPENSSL_DIR to point to where the openssl code is on your system:

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.

音盲 2025-01-17 21:23:21

我必须在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 导出 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

I had to set/export these openssl (brew installed) directories on Mac trying to compile a AWS Lambda Rust function:

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

This is part of the error message I was getting to hopefully help the coders still using Google in 2023:

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
花心好男孩 2025-01-17 21:23:21

尝试添加

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

到您的 Cargo.toml

try add

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

to your Cargo.toml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文