Last Updated: February 25, 2016
·
2.457K
· gzfrancisco

Problemas con OS X 10.8, Ruby, PostgreSQL, Rails y OpenSSL

Cuando actualice a mountain lion, tuve problemas con Ruby y PostgreSQL. El error era al compilar la extensión nativa.

Installing pg (0.14.0) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
 /Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
... 
creating Makefile
make
compiling pg.c
pg.c:273:9: warning: implicit declaration of function 'PQlibVersion' is invalid in C99 [-Wimplicit-function-declaration]
    return INT2NUM(PQlibVersion());
           ^
In file included from pg.c:48:
In file included from ./pg.h:17:
In file included from /Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby.h:32:
/Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:973:21: note: instantiated from:
# define INT2NUM(v) INT2FIX((int)(v))
...
... muchas notas parecidas a la anterior
...
pg.c:390:64: note: instantiated from:
    rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
                                                                  ^
1 warning and 4 errors generated.
make: *** [pg.o] Error 1


Gem files will remain installed in /Users/gzfrancisco/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0 for inspection.
Results logged to /Users/gzfrancisco/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/ext/gem_make.out
An error occurred while installing pg (0.14.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.0'` succeeds before bundling.

Cuando decides correr el ultimo comando entonces sale lo siguiente:

gem install pg -v '0.14.0'
Building native extensions. This could take a while...
^[[B^[[AERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for pgconfig... yes
Using config values from /usr/bin/pg
config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pgconfigmanual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for locreate()... yes
checking for pg
encodingtochar()... yes
checking for pgchartoencoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for rb
encdbalias()... yes
checking for rb
encalias()... no
checking for PGRES
COPY_BOTH in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile

make
compiling pg.c
pg.c:273:9: warning: implicit declaration of function 'PQlibVersion' is invalid in C99 [-Wimplicit-function-declaration]
return INT2NUM(PQlibVersion());
^
In file included from pg.c:48:
In file included from ./pg.h:17:
In file included from /Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby.h:32:
/Users/gzfrancisco/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:973:21: note: instantiated from:
define INT2NUM(v) INT2FIX((int)(v))
^
pg.c:273:9: note: instantiated from:
return INT2NUM(PQlibVersion());
^
pg.c:273:17: note: instantiated from:
return INT2NUM(PQlibVersion());
^
pg.c:384:48: error: use of undeclared identifier 'PQPINGOK'
rb
defineconst(rbmPGconstants, "PQPINGOK", INT2FIX(PQPINGOK));
^
pg.c:384:56: note: instantiated from:
rbdefineconst(rbmPGconstants, "PQPINGOK", INT2FIX(PQPINGOK));
^
pg.c:386:52: error: use of undeclared identifier 'PQPING
REJECT'
rbdefineconst(rbmPGconstants, "PQPINGREJECT", INT2FIX(PQPINGREJECT));
^
pg.c:386:60: note: instantiated from:
rb
defineconst(rbmPGconstants, "PQPINGREJECT", INT2FIX(PQPINGREJECT));
^
pg.c:388:57: error: use of undeclared identifier 'PQPINGNORESPONSE'
rbdefineconst(rbmPGconstants, "PQPINGNORESPONSE", INT2FIX(PQPINGNORESPONSE));
^
pg.c:388:65: note: instantiated from:
rb
defineconst(rbmPGconstants, "PQPINGNORESPONSE", INT2FIX(PQPINGNORESPONSE));
^
pg.c:390:56: error: use of undeclared identifier 'PQPINGNOATTEMPT'
rbdefineconst(rbmPGconstants, "PQPINGNOATTEMPT", INT2FIX(PQPINGNOATTEMPT));
^
pg.c:390:64: note: instantiated from:
rb
defineconst(rbmPGconstants, "PQPINGNOATTEMPT", INT2FIX(PQPINGNOATTEMPT));
^
1 warning and 4 errors generated.
make: *** [pg.o] Error 1

Gem files will remain installed in /Users/gzfrancisco/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0 for inspection.
Results logged to /Users/gzfrancisco/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/ext/gem_make.out

La solución es instalar postgresql con hombrebrew

brew install postgresql

Después haces el bundle install y al final vas a tener este error

rails s

WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
/Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.6/lib/activesupport/dependencies.rb:251:in `require': dlopen(/Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/pg-0.14.0/lib/pgext.bundle, 9): Library not loaded: @loaderpath/../lib/libssl.dylib (LoadError)
Referenced from: /usr/lib/libpq.5.dylib
Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8 - /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/pg-0.14.0/lib/pg
ext.bundle
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.6/lib/activesupport/dependencies.rb:251:in `block in require'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.6/lib/active
support/dependencies.rb:236:in load_dependency' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:inrequire'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/pg-0.14.0/lib/pg.rb:4:in <top (required)>' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:inrequire'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in block (2 levels) in require' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:ineach'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in block in require' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:ineach'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in require' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.2.0/lib/bundler.rb:128:inrequire'
from /Users/gzfrancisco/folder/directory/projects/nameproject/rails/code/nameproject/config/application.rb:7:in <top (required)>' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands.rb:53:inrequire'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands.rb:53:in block in <top (required)>' from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands.rb:50:intap'
from /Users/gzfrancisco/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands.rb:50:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `<main>'

Ahora el problema es openssl instalamos también openssl de homebrew

brew install openssl

Hay que hacer el link simbolico a la nueva libreria de openssl (http://stackoverflow.com/questions/11127486/rails-postgres-error-reason-incompatible-library-version-libpq-5-dylib-requ) link

sudo ln -s /usr/local/Cellar/openssl/1.0.1c/lib/libssl.dylib /usr/lib/libssl.dylib
sudo ln -s /usr/local/Cellar/openssl/1.0.1c/lib/libcrypto.dylib /usr/lib/libcrypto.dylib

Volvemos a intentar levantar el servidor

rails s

Con eso se debe resolver el problema. Saludos!

Muchas gracias a @ecamacho y a @juwe que me ayudaron con mi problema