2012-04-27 81 views
30

这个问题存在各种各样的问题,它们都围绕着SO进行反弹,但它们中的任何一个似乎都没有解决我的问题的答案。gem install pg在OSX Lion上不起作用

我正在运行OSX Lion(10.7.3)。最新的XCode已安装。

我已经使用postgresapp.com中的Postgres.app包安装了Postgres。

但是,当我尝试安装PG宝石,我得到一个错误:

$ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 
Building native extensions. This could take a while... 
ERROR: Error installing pg: 
    ERROR: Failed to build gem native extension. 

     /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 
Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config 
checking for libpq-fe.h... *** 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/disaacs/.rvm/rubies/ruby-1.9.3-p125/bin/ruby 
    --with-pg 
    --without-pg 
    --with-pg-dir 
    --without-pg-dir 
    --with-pg-include 
    --without-pg-include=${pg-dir}/include 
    --with-pg-lib 
    --without-pg-lib=${pg-dir}/lib 
    --with-pg-config 
/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/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/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:280:in `postpone' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for' 
    from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:969:in `find_header' 
    from extconf.rb:40:in `<main>' 


Gem files will remain installed in /Users/disaacs/.rvm/gems/ruby-1.9.3-p125/gems/pg-0.13.2 for inspection. 
Results logged to /Users/disaacs/.rvm/gems/ruby-1.9.3-p125/gems/pg-0.13.2/ext/gem_make.out 

/Applications/Postgres.app/Contents/MacOS/bin/pg_config命令的输出是:

$ /Applications/Postgres.app/Contents/MacOS/bin/pg_config 
BINDIR = /Applications/Postgres.app/Contents/MacOS/bin 
DOCDIR = /Applications/Postgres.app/Contents/MacOS/share/doc 
HTMLDIR = /Applications/Postgres.app/Contents/MacOS/share/doc 
INCLUDEDIR = /Applications/Postgres.app/Contents/MacOS/include 
PKGINCLUDEDIR = /Applications/Postgres.app/Contents/MacOS/include 
INCLUDEDIR-SERVER = /Applications/Postgres.app/Contents/MacOS/include/server 
LIBDIR = /Applications/Postgres.app/Contents/MacOS/lib 
PKGLIBDIR = /Applications/Postgres.app/Contents/MacOS/lib 
LOCALEDIR = /Applications/Postgres.app/Contents/MacOS/share/locale 
MANDIR = /Applications/Postgres.app/Contents/MacOS/share/man 
SHAREDIR = /Applications/Postgres.app/Contents/MacOS/share 
SYSCONFDIR = /Applications/Postgres.app/Contents/MacOS/etc 
PGXS = /Applications/Postgres.app/Contents/MacOS/lib/pgxs/src/makefiles/pgxs.mk 
CONFIGURE = '--prefix=/Users/mattt/Code/heroku/Postgres/Postgres/Vendor/postgres' '--enable-thread-safety' '--with-openssl' '--with-gssapi' '--with-bonjour' '--with-krb5' '--with-libxml' '--with-libxslt' '--with-ossp-uuid' '--with-perl' '--with-python' 
CC = gcc 
CPPFLAGS = -I/usr/include/libxml2 
CFLAGS = -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv 
CFLAGS_SL = 
LDFLAGS = -Wl,-dead_strip_dylibs 
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm 
VERSION = PostgreSQL 9.1.3 

所有这些设置似乎是正确的,但为CONFIGURE变量(这似乎是指其他一些计算机 - 我没有用户名为mattt)。

的mkmf.log文件的内容是

"/usr/bin/gcc-4.2 -o conftest -I/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin10.8.0 -I/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -I/Users/disaacs/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Applications/Postgres.app/Contents/MacOS/include -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib -L/Users/disaacs/.rvm/usr/lib -L. -L/usr/local/lib -L/Applications/Postgres.app/Contents/MacOS/lib  -lruby.1.9.1 -lpthread -ldl -lobjc " 
checked program was: 
/* begin */ 
1: #include "ruby.h" 
2: 
3: int main() {return 0;} 
/* end */ 

任何建议,将不胜感激。

我已经看过了extconf.rb文件,以及一些调试后我发现,它是

find_header ('libpq-fe.h') 

一个呼叫失败。不是因为libpq-fe.h不存在,而是因为find_header方法本身失败。我试图运行find_header使用内部评级法,并得到了同样的错误:

$ irb 
1.9.3-p125 :001 > require 'mkmf' 
=> true 
1.9.3-p125 :002 > find_header 'libpq-fe.h' 
checking for libpq-fe.h... RuntimeError: The compiler failed to generate an executable file. 
You have to install development tools first. 

编辑:

发现我的电脑必须更加borked比我想象的。我正在为另一个项目进行捆绑安装,并且安装sqlite3 gem时发生了类似的故障。

checking for sqlite3.h... *** extconf.rb failed *** 

我从来没有在过去的sqlite3宝石问题。

+0

http://stackoverflow.com/questions/8548809/pg-gem-install-on-mac-os-lion-with-rvm – mask8 2012-04-27 05:09:10

+1

该链接中的问题的解决方案是安装最新的XCode。我已经安装了最新的XCode。 – 2012-04-27 12:52:10

+0

您是否尝试过使用自制软件安装pq?另外值得一试的是看看'libpq'或'libpq-dev'软件包是否可用。 – tiredpixel 2012-04-27 23:43:17

回答

62

我终于找到了问题的原因!虽然我仍然不确定这个问题是如何产生的。

看时,我的安装命令失败创建(见我原来的职位)的mkmf.log文件的内容。它记录试图运行下面的命令

/usr/bin/gcc-4.2 ...and so on... 

有我的系统上没有/usr/bin/gcc-4.2。有一个gcc,它象征性地链接到llvm-gcc-4.2。我的解决方案是创建另一个符号链接

sudo ln -s llvm-gcc-4.2 gcc-4.2 

使这个链接后,我gem install pg命令的工作没有任何问题。

我发现在后Error Installing Ruby Gem with C Extension解决这个问题,在冰冻卡努克博客。他推测这个问题可能是由XCode版本冲突造成的。不管是什么原因,我永远的感谢!

+5

使用“sudo ln -s /usr/bin/{llvm-,}gcc-4.2”修复。谢谢! – grilix 2012-08-09 16:20:02

+0

我没有llvm-gcc-4.2 运行“brew install apple-gcc42”得到/usr/bin/gcc-4.2(10.9.1) – Maragues 2014-02-07 15:02:16

0

如果输出包括:

/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/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. 

那确实是你的编译环境的东西不对劲。特别是当故障是extconf.rb运行的第一个测试时。

如果您安装了XCode,那么您可能没有安装XCode的命令行工具组件?他们是recently split out from XCode proper,所以你需要分别安装它们。

+0

我原本没有安装命令行工具。但是安装它们没有任何区别。同样的错误仍在发生。 – 2012-04-28 03:15:07

15

我有类似的问题。继bobfet1的similar issue的答案,我能得到通过安装在宝石:

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 
+0

我试过了。没有区别。我刚刚发现了一些新的东西,并更新了我原来的帖子。 – 2012-05-05 03:07:55

+0

'pg'之后的'''单独的目的是什么?没有它们似乎不起作用,但我不知道它们是什么。 – jurassic 2013-11-12 09:44:35

+0

@jurassic从'gem help install':“你可能需要指定库的头文件和库的路径来继续[构建扩展]。你可以通过在RubyGems的选项和扩展的构建之间添加一个 - 选项”。一般来说,'--'的意思是“下面的参数不是选项。”例如。 'rm - -r'删除一个名为'-r'的文件。 – uasi 2014-02-04 03:11:32

2

我也遇到了这个问题,我的答案是更新万物RVM。

rvm get head 
rvm install 1.9.2 
+0

这不会将我的Ruby版本降级到1.9.2吗?我尝试升级到最新的RVM,但它没有任何区别。 – 2012-05-05 03:03:26

1

我在山狮,以及戴夫艾萨克斯接受的答案为我工作。我也不得不这样做

sudo ln -s llvm-g++-4.2 g++-4.2 
+3

我不需要在OS X 10.8.2上。 'sudo ln -s/usr/bin/{llvm - ,} gcc-4.2'工作。 – 2012-10-06 19:09:44

2

我也一样,我在山狮,除了“命令LN -s /usr/bin/{llvm-,}gcc-4.2”由@grilix的建议,我需要做的:

sudo ln -s /usr/bin/{llvm-,}g++-4.2 
1

比更新RVM本身(https://stackoverflow.com/a/10430742/2807795),如上述相反,它是没有的伎俩,试图在其他所有的步骤都没有成功后,Ruby的2.0.0-P247的重新安装。

rvm get head 
rvm install 2.0.0 
19

在OS X小牛

sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2 

作品。对小牛10.9

6

类似的问题 - 但它是由没有同意的Xcode许可协议引起的。布莱什。

运行sudo xcodebuild并同意垃圾。一切都按预期工作。

13

由于这个家伙:http://www.computersnyou.com/2025/

使用小牛:xcode-select --install(假设你已经安装了应用程序商店的Xcode)的作品。

+0

我不知道为什么这个问题没有被标记为答案,但是考虑到最初的问题,它绝对是最贴切的问题。谢谢@pjammer – 2014-04-27 19:11:38

2

小牛升级后...

重新安装您的红宝石版本。

rvm uninstall 1.9.2-p320 

然后

rvm install 1.9.2-p320 

,或者你有任何红宝石的版本。

1
$ gem install pg 

如果失败:

$ sudo gem install pg 

然后,如果失败:

$ sudo find/-name “pg_config” 

你找到pg_config的位置后,运行这个最终安装:

$ sudo gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.5.1/bin/pg_config 

当然,我想要改变路径到你发现的任何地方pg_config

然后,检查安装的宝石,gem list,它应该表现出这样的事情:

<code>gem list</code> showing the right things

的更多信息可以在my guide找到。