OpenSSL crate 在 Mac OS X 10.11 上编译失败 [英] OpenSSL crate fails compilation on Mac OS X 10.11

查看:24
本文介绍了OpenSSL crate 在 Mac OS X 10.11 上编译失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Mac OS X 10.11.2 上为 Rust 安装 Iron 框架,但是当我在编译 时运行 cargo buildcargo run 时失败了openssl 的东西:

I tried to install the Iron framework for Rust on Mac OS X 10.11.2, but it failed when I run cargo build or cargo run on compiling openssl's stuff:

failed to run custom build command for `openssl-sys-extras v0.7.4`
Process didn't exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-apple-darwin")
debug=true opt-level=0
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-fPIC" "-o" "/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/out/src/openssl_shim.o" "-c" "src/openssl_shim.c"
ExitStatus(Code(1))


command did not execute successfully, got: exit code: 1



--- stderr
src/openssl_shim.c:1:10: fatal error: 'openssl/hmac.h' file not found
#include <openssl/hmac.h>
     ^
1 error generated.
thread '<main>' panicked at 'explicit panic', /xxx/.cargo/registry/src/github.com-0a35038f75765ae4/gcc-0.3.21/src/lib.rs:772

openssl 版本似乎没问题:

$ openssl version
OpenSSL 0.9.8zg 14 July 2015

我不知道我必须做什么才能使此安装工作并尝试使用 Iron.

I don't know what I have to do in order to make this installation work and give Iron a try.

推荐答案

从 rust-openssl 0.8 版本开始,Homebrew 安装的 OpenSSL 库将被 crate 自动检测,无需设置额外的环境变量.

As of rust-openssl version 0.8, Homebrew-installed OpenSSL libraries will be automatically detected by the crate, there is no need to set extra environment variables.

如果您需要支持之前的版本或选择不使用 Homebrew,请继续阅读.

If you need to support a version prior to that or choose to not use Homebrew, read on.

这是一个已知问题(也是thisthis),但不是板条箱可以修复的.

This is a known issue (also this and this), but not one that the crate can fix.

快速解决方案是使用 Homebrew 安装 OpenSSL,然后通过设置 OPENSSL_INCLUDE_DIROPENSSL_LIB_DIR 环境变量明确指向找到 OpenSSL 的目录:

The quick solution is to install OpenSSL with Homebrew and then explicitly point to the directories where OpenSSL is found by setting the OPENSSL_INCLUDE_DIR and OPENSSL_LIB_DIR environment variables:

OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2e/include 
OPENSSL_LIB_DIR=/usr/local/Cellar/openssl/1.0.2e/lib 
cargo build

如果你已经完成了一个 cargo build,你需要先运行 cargo clean 来清除一些过时的缓存信息.

If you've already done one cargo build, you will need to run cargo clean first to clear our some stale cached information.

如果您不想为打开的每个 shell 设置此项,请将其添加到您的 shell 初始化文件中(如 ~/.bash_profile).您可以通过不对版本号进行硬编码来使其不那么脆弱:

If you don't want to set this for every shell you open, add it to your shell initialization files (like ~/.bash_profile). You can make it a bit less brittle by not hard-coding the version number:

export OPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include
export OPENSSL_LIB_DIR=$(brew --prefix openssl)/lib

如果您不想使用 Homebrew,请遵循相同的过程,但使用您的 OpenSSL 副本的适当路径.

If you don't want to use Homebrew, follow the same process but using the appropriate path to your copy of OpenSSL.

更长的原因很好由andrewtj描述:

OpenSSL 没有稳定的 ABI,因此出于兼容性目的,Apple 维护了一个与早期 ABI 之一兼容的分支.他们在 10.7 中弃用了 OpenSSL,并最终在 10.11 中删除了标头,以推动 OS X 应用程序开发人员捆绑他们自己的 OpenSSL 或使用他们的框架.dylib 已被保留,因此未更新的应用程序不会中断.您仍然可以链接它们,但这样做会导致奇怪的兼容性问题(除非您从早期的 OS X 版本中获取标头).

OpenSSL doesn't have a stable ABI so for compatibility purposes Apple have maintained a fork that's compatible with one of the earlier ABIs. They deprecated OpenSSL in 10.7 and finally dropped the headers in 10.11 to push OS X app developers toward bundling their own OpenSSL or using their frameworks. The dylibs have been left around so apps that haven't been updated don't break. You can still link against them but you're opening yourself up to odd compatibility issues by doing so (unless you grab the headers from an earlier OS X release).

这篇关于OpenSSL crate 在 Mac OS X 10.11 上编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆