无法在OS X Yosemite上构建puma gem

fea*_*ool 13 gem openssl ruby-on-rails puma

(修订)问题:

在我的OS X Yosemite(10.10.1)系统上安装puma gem需要什么?我已经用尽了许多途径(我有XCode工具,我有OpenSSL),但在尝试构建原生扩展时仍然失败.

问题

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

$ gem install puma
Run Code Online (Sandbox Code Playgroud)

我明白了:

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
Run Code Online (Sandbox Code Playgroud)

环境

我怀疑gem install无法找到SSL标头和/或库.这是我在我的系统上的内容(注意〜/ 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);
Run Code Online (Sandbox Code Playgroud)

另外,这里是如何编译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. 
Run Code Online (Sandbox Code Playgroud)

问题

我只是缺少构建过程的一些配置标志吗?我或多或少随机尝试了一堆标志:

$ 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
Run Code Online (Sandbox Code Playgroud)

但在每种情况下得到相同的错误.有人能告诉我我缺少的东西吗?

更多信息...

带有错误的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; }
Run Code Online (Sandbox Code Playgroud)

当我浏览我的沙盒目录树时,唯一定义SSL_CTX_new的头文件是~/sandbox/include/openssl/ssl.h.看来该文件没有被包含在内,我目前还不知道为什么.

Den*_*est 38

对于那些遇到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
Run Code Online (Sandbox Code Playgroud)

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


fea*_*ool 1

事实证明,这是 puma 2.9.2+ 版本中的一个错误,并已在 2.11.0 版本中修复。有关详细信息,请参阅https://github.com/puma/puma/issues/627https://github.com/puma/puma/pull/628

(unix 用户请注意:如果仍然遇到问题,请确保首先安装了 libssl-dev。)