ruby-on-rails - 无法在 OS X Yosemite 上构建 puma gem

标签 ruby-on-rails gem openssl puma

(修订)问题:

在我的 OS X Yosemite (10.10.1) 系统上安装 puma gem 需要什么?我已经用尽了很多方法(我有 XCode 工具,我有 OpenSSL),但是在尝试构建 native 扩展时它仍然失败。

问题

在我的 OS X 系统上,当我这样做时:

$ gem install puma

我得到:
Building native extensions.  This could take a while...
ERROR:  Error installing puma:
        ERROR: Failed to build gem native extension.

    /Users/home/sandbox/usr/bin/ruby extconf.rb
checking for SSL_CTX_new() in -lssl... no
checking for SSL_CTX_new() in -lssleay32... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/home/sandbox/usr/bin/ruby
        --with-puma_http11-dir
        --without-puma_http11-dir
        --with-puma_http11-include
        --without-puma_http11-include=${puma_http11-dir}/include
        --with-puma_http11-lib
        --without-puma_http11-lib=${puma_http11-dir}/lib
        --with-ssllib
        --without-ssllib
        --with-ssleay32lib
        --without-ssleay32lib

extconf failed, exit code 1

Gem files will remain installed in /Users/home/sandbox/usr/lib/ruby/gems/2.1.0/gems/puma-2.10.2 for inspection.
Results logged to /Users/home/sandbox/usr/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0/puma-2.10.2/gem_make.out

环境

我怀疑 gem install无法找到 SSL header 和/或库。这是我的系统上的内容(注意 ~/sandbox/usr 是我的“沙箱”目录,包含我的 Ruby on Rails 开发的所有可执行文件、库、头文件等)。请注意,“ssl.h”确实定义了 SSL_CTX_new():
$ which openssl
~/sandbox/usr/bin/openssl
$ openssl version
OpenSSL 1.0.1j 15 Oct 2014
$ openssl version -d
OPENSSLDIR: "/Users/home/sandbox/usr/ssl"
$ find ~/sandbox/usr -name "*libssl*" -print
~/sandbox/usr/lib/libssl.a
$ find ~/sandbox/usr -name "*.h" -exec grep SSL_CTX_new {} /dev/null \;
~/sandbox/usr/include/openssl/ssl.h:SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);

此外,这里是 ruby​​ 的编译方式。 $INSTALL_DIR 是 ~/home/sandbox:
./configure --prefix=$(INSTALL_DIR) --enable-shared --disable-install-doc --with-opt-dir=$(INSTALL_DIR) --with-openssl-dir=$(INSTALL_DIR)/bin; where INSTALL_DIR is ~/sandbox/usr. 

问题

我是否只是缺少构建过程的一些配置标志?我或多或少地随机尝试了一堆标志:
$ gem install puma -- --with-openssl-dir=/Users/home/sandbox/usr/ssl
$ gem install puma -- --with-ssllib=/Users/home/sandbox/usr/lib/libssl.a 
$ gem install puma -- --with-ssl=/Users/home/sandbox/usr/bin/openssl
$ gem install puma -- --with-ssl=/Users/home/sandbox/usr/bin
$ gem install puma -- --with-opt-dir=/Users/home/sandbox/usr

但在每种情况下都出现相同的错误。有人能告诉我我错过了什么吗?

更多信息...

带有错误的 mkmf.log 文件如下所示(为了可读性添加了换行符):
"clang -o conftest 
-I/Users/home/sandbox/usr/include/ruby-2.1.0/x86_64-darwin14.0 
-I/Users/home/sandbox/usr/include/ruby-2.1.0/ruby/backward 
-I/Users/home/sandbox/usr/include/ruby-2.1.0 
-I.  
-I/Users/home/sandbox/usr/include 
-D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    
-O3 -fno-fast-math -ggdb3 -Wall -Wextra 
-Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers 
-Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement 
-Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens  
-fno-common -pipe conftest.c  
-L. 
-L/Users/home/sandbox/usr/lib 
-L/Users/home/sandbox/usr/lib 
-L. -fstack-protector 
-L/Users/home/sandbox/usr/lib      
-lruby.2.1.0 -lssl  -lpthread -ldl -lobjc "

conftest.c:13:57: error: use of undeclared identifier 'SSL_CTX_new'

int t(void) { void ((*volatile p)()); p = (void ((*)()))SSL_CTX_new; return 0; }

当我浏览沙箱目录树时,唯一定义 SSL_CTX_new 的头文件是 ~/sandbox/include/openssl/ssl.h .似乎没有包含该文件,我目前不知道为什么。

最佳答案

对于在使用 puma 和 openssl 时遇到问题的人,尤其是在 Mac OS 10.11 (El Capitan) 中,添加一些标志将为您节省数小时和数小时的心痛:

gem install puma -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib

https://gist.github.com/edvinasbartkus/0e99ea8305a20737f562

关于ruby-on-rails - 无法在 OS X Yosemite 上构建 puma gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27465544/

相关文章:

java - 如何使用 EVP_Sign 函数计算签名

javascript - 在 JavaScript 中为我的 Rails 应用程序显示弹出消息

html - 自动完成以及如何让它理解小写和大写

ruby-on-rails - JSON gem : Failing to build gem native extension, Windows 7 上的 bundle 安装失败

ruby-on-rails - Rails 功能测试用例和上传文件到 ActionDispatch::Http::UploadFile

java - 在 Java 中加载 RSA 私钥(algid 解析错误,不是序列)

git - 致命的 : unable to access 'https://github.com/xxx' : LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github. com:443

ruby-on-rails - 如何在Mongoid中强制执行唯一的嵌入式文档

mysql按多数票排序

ruby-on-rails-3 - Rest on Rails 3 的助手 Gem