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

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

问题描述

这个问题在这个问题上有些变化,但他们都没有解决我的问题。



我正在运行OSX Lion(10.7。 3)。安装了最新的XCode。



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



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

  $ gem install pg  -  --with-pg-config = / Applications / Postgres.app / Contents / MacOS / bin / pg_config 
构建本机扩展。这可能需要一段时间...
错误:安装pg时出错:
错误:无法构建gem本机扩展。

/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb --with-pg-config = / Applications / Postgres.app / Contents / MacOS / bin / pg_config
使用/Applications/Postgres.app/Contents/MacOS/bin/pg_config中的配置值
检查libpq-fe.h ... *** extconf.rb失败***
由于某种原因无法创建Makefile,可能缺少
必需的库和/或头文件。查看mkmf.log文件以获取更多
的详细信息。您可能需要配置选项。

提供的配置选项:
--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 $ b $ --with-pg-config
/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:381:in`try_do':编译器无法生成可执行文件。 (RuntimeError)
您必须先安装开发工具。从/ Users / disaacs中从/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:506:in`try_cpp'
获得
/.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:在`block in checking_for'
from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/ lib / ruby​​ / 1.9.1 / mkmf.rb:284:在`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:在`block in postpone'
from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in`open'$ b / b from /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:280:in`推迟'
from / Users / disaacs / .rvm / rubies / ruby​​-1.9.3-p125 / lib / ruby​​ / 1.9.1 / mkmf.rb:789:来自/Users/disaacs/.rvm/rubies/ruby-1.9的`checking_for'
。 3 -p125 / lib / ruby​​ / 1.9.1 / mkmf.rb:969:在`find_header'中
从extconf.rb:40:在< main>'


Gem文件将保留安装在/Users/disaacs/.rvm/gems/ruby-1.9.3-p125/gems/pg-0.13.2中进行检查。
结果记录到/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 = /应用程序/Postgres.app/Contents/MacOS/share/locale
MANDIR = /Applications/Postgres.app/Contents/MacOS/share/man
SHARED IR = /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文件的内容是 p>

 / 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-括号-Wno- long-long -Wno-missing-field-initializers -Winterinter-arith -Wwrite-strings -Wclaclaration-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 /目录/ MacOS / lib -lruby.1.9.1 -lpthread -ldl -lobjc
检查程序为:
/ * begin * /
1:#includeruby.h
2:
3:int main(){return 0;}
/ * end * /

任何建议,将不胜感激。



我看过extconf.rb文件,并在一些调试后,我发现它是一个调用

  find_header('libpq-fe .h')

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

  $ irb 
1.9.3-p125:001> require'mkmf'
=> true
1.9.3-p125:002> find_header'libpq -fe.h'
检查libpq-fe.h ... RuntimeError:编译器无法生成可执行文件
您必须先安装开发工具

编辑:

计算机必须比我想象的要更加博古。我正在为另一个项目进行捆绑安装,并且安装sqlite3 gem时出现类似的错误。

 检查sqlite3.h ... *** extconf.rb失败*** 

我从来没有遇到问题sqlite3 gem在过去。

解决方案

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



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

  /usr/bin/gcc-4.2 ...等等... 

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

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

code>

完成此链接后,我的 gem install pg 命令无任何问题。



我在Frozen Canuck博客的在C扩展中安装Ruby Gem时出错。他推测这个问题可能是由XCode版本冲突造成的。不管是什么原因,我的永恒感谢!

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). The latest XCode is installed.

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

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

The output of the /Applications/Postgres.app/Contents/MacOS/bin/pg_config command is:

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

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

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

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

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.

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

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.

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

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 

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

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天全站免登陆