简体   繁体   English

gem install pg在OSX Lion上不起作用

[英]gem install pg doesn't work on OSX Lion

There are variations of this question bouncing around SO, but none of them seem to have an answer that solves my problem. 这个问题有各种各样的变化,但是它们似乎都没有解决我问题的答案。

I am running OSX Lion (10.7.3). 我正在运行OSX Lion(10.7.3)。 The latest XCode is installed. 安装了最新的XCode。

I've installed Postgres using the Postgres.app package from postgresapp.com. 我使用postgresapp.com的Postgres.app包安装了Postgres。

But when I try to install the pg gem, I get a failure: 但是当我尝试安装pg gem时,我遇到了失败:

$ 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

The output of the /Applications/Postgres.app/Contents/MacOS/bin/pg_config command is: /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

All those setting appear to be correct, except for the CONFIGURE variable (which seems to be referring to some other computer --I have no user named mattt). 所有这些设置看起来都是正确的,除了CONFIGURE变量(这似乎是指其他一些计算机 - 我没有用户名为mattt)。

The contents of the mkmf.log file are 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 */

Any suggestions would be appreciated. 任何建议,将不胜感激。

I've looked at the extconf.rb file, and after some debugging I've found that it is a call to 我查看了extconf.rb文件,经过一些调试后我发现它是一个调用

find_header ('libpq-fe.h')

that is failing. 那是失败的。 Not because libpq-fe.h is not there, but because the find_header method itself is failing. 不是因为libpq-fe.h不存在,而是因为find_header方法本身失败了。 I tried running find_header using irb, and got the same error: 我尝试使用irb运行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.

EDIT: 编辑:

Found out my computer must be even more borked than I thought. 发现我的电脑必须比我想象的更加烦躁。 I was doing bundle install for another project, and I got a very similar failure installing the sqlite3 gem. 我正在为另一个项目进行bundle install,我在安装sqlite3 gem时遇到了类似的失败。

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

I've never had problems with the sqlite3 gem in the past. 我以前从未遇到过sqlite3 gem的问题。

I finally found the cause of the problem! 我终于找到了问题的原因! Though I am still uncertain how this problem came about. 虽然我仍然不确定这个问题是如何产生的。

Look at the contents of the mkmf.log file that is created when my install command fails (see my original post). 查看我的安装命令失败时创建的mkmf.log文件的内容(请参阅我的原始帖子)。 It logs an attempt to run the following command 它记录尝试运行以下命令

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

There is no /usr/bin/gcc-4.2 on my system. 我的系统上没有/usr/bin/gcc-4.2 There is a gcc , which is symbolically linked to llvm-gcc-4.2 . 有一个gcc ,象征性地链接到llvm-gcc-4.2 My solution was to create another symbolic link 我的解决方案是创建另一个符号链接

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

After making this link, my gem install pg command worked without any problems. 建立此链接后,我的gem install pg命令没有任何问题。

I found the solution to this problem on the Frozen Canuck blog in the post Error Installing Ruby Gem with C Extension . 我发现在使用C扩展安装Ruby Gem错误后,在Frozen Canuck博客上找到了这个问题的解决方案。 He speculates that the problem can be caused by conflicting versions of XCode. 他推测这个问题可能是由XCode的冲突版本引起的。 whatever the cause, my eternal thanks! 不管是什么原因,我永远的感谢!

On OS X Mavericks 在OS X Mavericks上

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

works. 作品。

I had a similar issue. 我有一个类似的问题。 Following an answer by bobfet1 for a similar issue I was able to get the gem installed by: 根据bobfet1对类似问题的回答,我能够通过以下方式安装gem:

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

Thanks to this guy: http://www.computersnyou.com/2025/ 感谢这个家伙: http//www.computersnyou.com/2025/

On Mavericks using: xcode-select --install (assuming you have installed Xcode from the app store) works. 在Mavericks上使用: xcode-select --install (假设你已经从app store安装了Xcode)。

Installing xcode from the app store is not enough. 从应用程序商店安装xcode是不够的。 You will also need xcode's command line tools. 您还需要xcode的命令行工具。 https://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_3.html https://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_3.html

After installing xcode from the app store, open xcode. 从应用商店安装xcode后,打开xcode。 Goto Xcode->Open Developer Tool->More Developer Tools Download and install the latest command line tools. 转到Xcode-> Open Developer Tool-> More Developer Tools下载并安装最新的命令行工具。

Open a terminal window and run: sudo gem install pg 打开终端窗口并运行:sudo gem install pg

Similar problem on Mavericks 10.9 -- but it was caused by not having agreed to the Xcode license agreement. 小牛10.9上的类似问题 - 但它是由于未同意Xcode许可协议引起的。 Blech. 布莱什。

Run sudo xcodebuild and agree to the junk. 运行sudo xcodebuild并同意垃圾。 The everything works as expected. 一切都按预期工作。

I also ran into this issue, for me the answer was updating RVM of all things. 我也碰到了这个问题,对我来说答案是更新所有东西的RVM。

rvm get head
rvm install 1.9.2

我也是Mountain Lion,除了@grilix建议的“sudo ln -s /usr/bin/{llvm-,}gcc-4.2”之外,我还需要这样做:

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

After a Mavericks upgrade... 小牛升级后......

Reinstall your ruby version. 重新安装您的ruby版本。

rvm uninstall 1.9.2-p320

then 然后

rvm install 1.9.2-p320

or whatever version of ruby you have. 或者你拥有的任何版本的红宝石。

I am on Mountain Lion, and the accepted answer from Dave Isaacs worked for me. 我在Mountain Lion,Dave Isaacs接受的答案对我有用。 I also had to do 我也必须这样做

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

Rather than updating RVM itself ( https://stackoverflow.com/a/10430742/2807795 ), as above, it was the reinstallation of Ruby 2.0.0-p247 that did the trick, after trying all the other steps above without success. 如上所述,不是更新RVM本身( https://stackoverflow.com/a/10430742/2807795 ),而是在重复上述所有其他步骤而没有成功之后重新安装了Ruby 2.0.0-p247。

rvm get head
rvm install 2.0.0
$ gem install pg

If that failed: 如果失败了:

$ sudo gem install pg

Then, if that failed: 然后,如果失败了:

$ sudo find / -name “pg_config”

After you find pg_config 's location, run this to finally install it: 找到pg_config的位置后,运行它以最终安装它:

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

Of course, you'll want to change the path to wherever you found pg_config . 当然,您需要将路径更改为找到pg_config

Then, check your installed gems with gem list , and it should show something like this: 然后,使用gem list检查已安装的gem,它应该显示如下:

<code> gem list </ code>显示正确的事情

More information can be found in my guide . 更多信息可以在我的指南中找到。

If the output includes: 如果输出包括:

/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.

then there really is something amiss with your compilation environment. 然后你的编译环境确实有些不对劲。 Especially when the failure is the very first test that extconf.rb runs. 特别是当失败是extconf.rb运行的第一个测试时。

If you have XCode installed, then perhaps you don't have the command-line tools component of XCode installed? 如果您安装了XCode,那么您可能没有安装XCode的命令行工具组件? They were recently split out from XCode proper , so you need to install them separately. 它们最近从XCode中分离出来 ,因此您需要单独安装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM