gem install pg 在 OSX Lion 上不起作用 [英] gem install pg doesn't work on OSX Lion

查看:37
本文介绍了gem install pg 在 OSX Lion 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有很多变体,但似乎没有一个可以解决我的问题.

There are variations of this question bouncing around SO, but none of them seem to have an answer that solves my problem.

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

I am running OSX Lion (10.7.3). The latest XCode is installed.

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

I've installed Postgres using the Postgres.app package from postgresapp.com.

但是当我尝试安装 pg gem 时,我遇到了失败:

But when I try to install the pg gem, I get a failure:

$ 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 的用户).

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

mkmf.log文件的内容是

The contents of the mkmf.log file are

"/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 文件,经过一些调试我发现它是对

I've looked at the extconf.rb file, and after some debugging I've found that it is a call to

find_header ('libpq-fe.h')

那是失败的.不是因为 libpq-fe.h 不存在,而是因为 find_header 方法本身失败了.我尝试使用 irb 运行 find_header,得到了同样的错误:

that is failing. Not because libpq-fe.h is not there, but because the find_header method itself is failing. I tried running find_header using irb, and got the same error:

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

发现我的电脑肯定比我想象的还要糟糕.我正在为另一个项目进行捆绑安装,安装 sqlite3 gem 时遇到了非常相似的失败.

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.

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

我过去从未遇到过使用 sqlite3 gem 的问题.

I've never had problems with the sqlite3 gem in the past.

推荐答案

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

I finally found the cause of the problem! Though I am still uncertain how this problem came about.

查看我的安装命令失败时创建的 mkmf.log 文件的内容(请参阅我的原始帖子).它记录了运行以下命令的尝试

Look at the contents of the mkmf.log file that is created when my install command fails (see my original post). It logs an attempt to run the following command

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

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

There is no /usr/bin/gcc-4.2 on my system. There is a gcc, which is symbolically linked to llvm-gcc-4.2. My solution was to create another symbolic link

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

创建此链接后,我的 gem install pg 命令正常运行.

After making this link, my gem install pg command worked without any problems.

我在 Frozen Canuck 博客上的帖子 Error Installation Ruby Gem 中找到了解决此问题的方法带有 C 扩展名.他推测问题可能是由 XCode 的版本冲突引起的.不管是什么原因,我永远的感谢!

I found the solution to this problem on the Frozen Canuck blog in the post Error Installing Ruby Gem with C Extension. He speculates that the problem can be caused by conflicting versions of XCode. whatever the cause, my eternal thanks!

这篇关于gem install pg 在 OSX Lion 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆