13

(Revised) question:

What does it take install puma gem on my OS X Yosemite (10.10.1) system? I've exhausted a bunch of avenues (I have XCode tools, I have OpenSSL), but it still fails while trying to build the native extensions.

The Problem

On my OS X system, when I do:

$ 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

The Environment

I suspect that gem install is unable to locate the SSL headers and/or libraries. Here's what I've got on my system (note that ~/sandbox/usr is my "sandbox" directory, containing all executables, libraries, headers, etc for my Ruby on Rails development). Notice that "ssl.h" does define 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);

Also, here's how ruby was compiled. $INSTALL_DIR is ~/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. 

The Question

Am I simply missing some configuration flags for the build process? I've tried a bunch of flags more or less at random:

$ 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

but got the same error in each case. Can someone clue me in to what I'm missing?

more info...

The mkmf.log file with the error looks like this (line breaks added for readability):

"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; }

As I grovel through my sandbox directory tree, the only header file that defines SSL_CTX_new is ~/sandbox/include/openssl/ssl.h. It appears that that file isn't being included, and I'm currently at a loss as to why.

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • 1
    Perhaps I've foolishly squandered bounty points: I can get puma v2.9.1 to install just fine, but v2.9.2 onwards shows the above problem. I've filed an issue on the puma repository. I'll happily give the bounty points to anyone who can tell the puma developers what needs fixing. – fearless_fool Dec 18 '14 at 21:51
  • I looked at the issue that you filed on gh...good that you found a solution...I am interested in that my team runs puma on all our apps and have had no issues with puma since OSX upgrade...only difference is we manage our ruby installs with rvm and rbenv. – tagCincy Dec 20 '14 at 06:11

4 Answers4

39

For people who are having issues with puma and openssl, particularly with Mac OS 10.11 (El Capitan), adding some flags will save you hours and hours of heartache:

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

Dennis Best
  • 3,614
  • 3
  • 20
  • 31
  • Great! You just saved my an allnighter – Vernon Oct 13 '15 at 18:38
  • you sir... saved my day :D – sameera207 Oct 23 '15 at 04:53
  • @Dennis Best Thank you kind sir, saved me hours of researching. You definitely should make this into a community wiki for other people. [Public Wiki with reference](http://stackoverflow.com/questions/33863980/problems-installing-puma-ruby-gem-on-os-x-el-capitan-10-11/33863981#33863981) – djowinz Nov 23 '15 at 04:56
  • If anyone has problem with heroku Getting start and stuck with 'bundle install' error gem puma not install correctly just use this script and add '-v 2.9.1' – Norak Jan 06 '16 at 07:49
  • @Dennis, Worked for me, I tried almost everything before this – Arpit Tyagi Feb 08 '16 at 22:06
1

Turns out this was a bug in puma versions 2.9.2+ and has been fixed in version 2.11.0. For details, see https://github.com/puma/puma/issues/627 and https://github.com/puma/puma/pull/628.

(Note to unix users: if you're still having trouble, make sure you've have libssl-dev installed first.)

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
1

I had a similar issue on OSx El Capitan. Here's what has helped me:

brew install openssl
brew link --force openssl
Konstantin Rudy
  • 2,237
  • 25
  • 22
0

Was your Ruby installation definitely configured with --with-openssl-dir? (Usually a not-fun part of the process.) You can require 'openssl'?

I'm able to install puma with a similar configuration without any flags. (And I think having OpenSSL installed under your home directory is a wise decision.)

TK-421
  • 10,598
  • 3
  • 38
  • 34
  • (Ooops -- silly 5 minute edit limit!) Yes: ruby was compiled with `./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`. And rails runner "puts require 'openssl'" => "true", so it seems that openssl is present. – fearless_fool Dec 14 '14 at 02:36
  • Was going to post mine, too, which also included `--with-gcc=clang` (but I'm not sure if that's relevant here). – TK-421 Dec 14 '14 at 02:38
  • As I stare at mkmf.log more, I see that the problem is that it can't find the header file that defines SSL_CTX_new() -- it has nothing to do with the loader or lib files. What I *don't* see is how the relevant header file (~/sandbox/usr/include/openssl/ssl.h) ever gets included. – fearless_fool Dec 14 '14 at 03:45
  • Have you already checked out Puma's issues list? (For example: https://github.com/puma/puma/issues/599) – TK-421 Dec 14 '14 at 10:47
  • I had configured Ruby with `--with-openssl-dir=/Users/u/opt/openssl` (above `bin`). – TK-421 Dec 14 '14 at 10:51