我试图在Mac OS X 10.11.2上安装铁 rust 框架,但在编译openssl的东西时运行cargo buildcargo run失败:

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

我不知道我要做什么才能让这个安装工作,并try 一下熨斗.

推荐答案

从rust openssl版本0.8开始,机箱将自动检测brew 安装的openssl库,无需设置额外的环境变量.

如果您需要支持之前的版本,或者 Select 不使用brew 软件,请继续阅读.


这是一个known issue(也是thisthis),但不是一个 crate 可以修复.

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

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来清除一些过时的缓存信息.

如果你不想为你打开的每一个shell设置这个值,那么把它添加到你的shell初始化文件中(比如~/.bash_profile).您可以通过不硬编码版本号来降低其脆弱性:

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

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


更长期的原因是:

OpenSSL没有一个稳定的ABI,所以为了兼容,苹果保留了一个与早期ABI兼容的Forking .他们在10.7中弃用了OpenSSL,最后在10.11中删除了标题,以推动OS X应用程序开发人员Bundle 自己的OpenSSL或使用他们的框架.DYLIB被保留了下来,所以没有更新的应用程序不会崩溃.你仍然可以链接它们,但这样做会让你自己面临奇怪的兼容性问题(除非你从早期的OS X版本中获取标题).

Rust相关问答推荐

为潜在的下游实现使用泛型绑定而不是没有泛型绑定的trait

铁 rust 中的共享对象实现特征

将PathBuf转换为字符串

Rust函数的返回值不能引用局部变量或临时变量

如何将实现多个特征的 struct 传递给接受这些特征为&;mut?

什么时候使用FuturesOrdered?

Cargo.toml:如何有条件地启用依赖项功能?

Const 上下文:从 init 函数创建具有 const 通用长度的数组

Rust 中的静态引用

Nom 解析器无法消耗无效输入

根据掩码将 simd 通道设置为 0 的惯用方法?

在 Rust 中忽略 None 值的正确样式

为什么这段 Rust 代码会在没有递归或循环的情况下导致堆栈溢出?

pyO3 和 Panics

Rust Redis 中的 HSET 命令问题

在给定 Rust 谓词的情况下,将 Some 转换为 None 的惯用方法是什么?

如果不满足条件,如何在 Rust 中引发错误

`map` 调用在这里有什么用吗?

`use std::error::Error` 声明中断编译

如何重写这个通用参数?