无法在OS X Yosemite上构建puma gem

13

修订后的问题:

我应该怎样在我的OS X Yosemite(10.10.1)系统上安装puma gem?我已经尝试了很多方法(我有XCode工具,我有OpenSSL),但是在构建本地扩展时仍然失败。

问题描述

在我的OS X系统上,当我执行以下命令:

$ gem install puma

I get:

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头文件和/或库。以下是我的系统信息(请注意,~/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。看起来这个文件没有被包含进去,目前我不知道为什么。

1
也许我愚蠢地浪费了赏金点数:我可以很好地安装puma v2.9.1,但是v2.9.2及以上版本显示上述问题。我已在puma存储库上提交了一个问题。我很乐意将赏金点数给任何能告诉puma开发人员需要修复什么的人。 - fearless_fool
我看了你在gh上提交的问题...很好,你找到了解决方案...我对于我的团队在所有应用程序上运行puma并且自OSX升级以来没有遇到任何问题感兴趣...唯一的区别是我们使用rvm和rbenv管理我们的ruby安装。 - tagCincy
4个回答

39

对于那些在Mac OS 10.11(El Capitan)上遇到puma和openssl问题的人,添加一些标志将节省您数小时的痛苦:

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


太好了!你刚刚挽救了我整整一晚的熬夜。 - Vernon
您,先生,救了我的一天 :D - sameera207
@Dennis Best 谢谢您,亲切的先生,您为我节省了数小时的研究时间。您绝对应该将这转为一个公共维基,以供其他人使用。公共维基参考链接 - djowinz
如果有人在使用Heroku时遇到问题,并且在'bundle install'错误gem puma未正确安装的情况下被卡住,只需使用此脚本并添加'-v 2.9.1'即可。 - Norak
@Dennis,对我有用,我在这之前尝试了几乎所有的方法。 - Arpit Tyagi

1

我在OSx El Capitan上遇到了类似的问题。以下是帮助我的方法:

brew install openssl
brew link --force openssl

1

0

你的 Ruby 安装是否明确配置了 --with-openssl-dir?(通常是过程中不太愉快的一部分。)你可以 require 'openssl' 吗?

我能够使用类似的配置安装 puma 而不需要任何标志。(我认为在您的主目录下安装 OpenSSL 是一个明智的决定。)


是的:Ruby 是使用 ./configure --prefix=$(INSTALL_DIR) --enable-shared --disable-install-doc --with-opt-dir=$(INSTALL_DIR) --with-openssl-dir=$(INSTALL_DIR)/bin; 编译的,其中 INSTALL_DIR 是 ~/sandbox/usr。而且 Rails 运行 "puts require 'openssl'" => "true",所以看起来 OpenSSL 已经存在了。 - fearless_fool
我本来也想发表我的,它还包括 --with-gcc=clang(但我不确定这是否与此相关)。 - TK-421
当我仔细查看mkmf.log时,我发现问题在于它找不到定义SSL_CTX_new()的头文件 - 这与加载器或lib文件无关。我没有看到相关的头文件(〜/ sandbox / usr / include / openssl / ssl.h)是如何被包含的。 - fearless_fool
你是否已经查看了 Puma 的问题列表?(例如:https://github.com/puma/puma/issues/599) - TK-421
我已经使用 --with-openssl-dir=/Users/u/opt/openssl(在 bin 上面)配置了 Ruby。 - TK-421

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接