无法在OSX 10.10上安装pg gem

时间:2014-10-20 13:53:00

标签: ruby xcode compilation pg osx-yosemite

我正在尝试使用以下命令在我的系统上安装pg gem(macbook pro运行10.10,Postgresql 9.3.5_1,Ruby 1.9.3p547,Xcode v6.1(6A1052c)):

ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

返回:

Building native extensions with: '--with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
Using config values from /usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
*** 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/thomas/.rvm/rubies/ruby-1.9.3-p547/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from extconf.rb:39:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/thomas/.rvm/gems/ruby-1.9.3-p547/gems/pg-0.17.1 for inspection.
Results logged to /Users/thomas/.rvm/gems/ruby-1.9.3-p547/extensions/x86_64-darwin-13/1.9.1/pg-0.17.1/gem_make.out

什么?

我很确定我安装了开发人员工具:

xcode-select --print-path

返回:

/Applications/Xcode.app/Contents/Developer

我的mkmf.log文件包含:

"/usr/local/opt/gcc46/bin/gcc-4.6 -o conftest -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1/x86_64-darwin13.4.0 -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1/ruby/backward -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1 -I. -I/usr/local/Cellar/postgresql/9.3.5_1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include  -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fno-common -pipe conftest.c  -L. -L/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib -L/usr/local/Cellar/postgresql/9.3.5_1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L.  -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib      -lruby.1.9.1  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

有没有人知道这里发生了什么?任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:6)

这解决了我的问题

首先,您应该下载Postgres应用程序(http://postgresapp.com/)并将其放在“应用程序”文件夹中。解压缩并打开它,现在将其写入控制台。

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

我写了9.4因为这是我的最新版本。

答案 1 :(得分:0)

我终于通过撕掉我所有的红宝石来解决这个问题:rvm implode。然后我重新安装了rvm和Ruby 2.1.3而不是1.9.3。可悲的是,我不确切地知道问题的原因是什么,但我怀疑是Ruby 1.9.3 does not install nicely with rvm on OSX 10.10