我尝试在Mac OS X 10.11.2上为Rust安装Iron框架,但是当我运行cargo build
或cargo run
编译时它失败了openssl
:
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^ 1 error generated. thread ' ' 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.
从rust-openssl版本0.8开始,Homebrew安装的OpenSSL库将被包自动检测到,不需要设置额外的环境变量.
如果您需要先支持之前的版本或选择不使用Homebrew,请继续阅读.
这是一个已知问题(也是这个和这个),但不是箱子可以解决的问题.
快速解决方案是使用Homebrew安装OpenSSL,然后通过设置OPENSSL_INCLUDE_DIR
和OPENSSL_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
如果您不想使用Homebrew,请遵循相同的过程,但使用适当的OpenSSL副本路径.
更长的原因由andrewtj描述:
OpenSSL没有稳定的ABI,因此出于兼容性目的,Apple已经维护了一个与早期ABI兼容的分支.他们在10.7中弃用了OpenSSL,并最终在10.11中删除了标题,以推动OS X应用程序开发人员捆绑他们自己的OpenSSL或使用他们的框架.dylib已被留下,因此尚未更新的应用程序不会中断.你仍然可以链接它们,但是这样做会打开你自己的奇怪的兼容性问题(除非你从早期的OS X版本中获取标题).
使用Brew这样:
brew install openssl export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib cargo clean cargo build