pg gem 安装错误 - lion osx、bundler 和 rvm

Posted

技术标签:

【中文标题】pg gem 安装错误 - lion osx、bundler 和 rvm【英文标题】:pg gem install error - lion osx, bundler, and rvm 【发布时间】:2012-02-01 04:38:50 【问题描述】:

我花了太多时间试图解决这个问题。

我重新格式化了我的电脑 - 清洁雪豹,而不是立即升级到狮子。

已安装 Xcode 4.2.1

RVM 已安装

在我设置环境时,我终于开始捆绑安装,但尝试创建 PG gem 失败。

我使用 macports 安装了 postgresql(不知道它预装在 lion 中)。按照此处的说明:http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x 并在尝试安装 pg gem 时遇到更多错误:

Installing pg (0.12.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/me/.rvm/rubies/ruby-1.8.7-p357/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
    --without-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/sling31/.rvm/rubies/ruby-1.8.7-p357/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
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/me/.rvm/gems/ruby-1.8.7-p357/gems/pg-0.12.0 for inspection.
Results logged to /Users/me/.rvm/gems/ruby-1.8.7-p357/gems/pg-0.12.0/ext/gem_make.out
An error occured while installing pg (0.12.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.0'` succeeds before bundling.

我已经不停地搜索了 ***,并且几乎尝试了所有方法。

我删除了 macports 版本,然后决定尝试使用 homebrew 安装:

"brew 安装 postgresql"

pg_config 给我:

BINDIR = /usr/local/Cellar/postgresql/9.1.2/bin
DOCDIR = /usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql
htmlDIR = /usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql
INCLUDEDIR = /usr/local/Cellar/postgresql/9.1.2/include
PKGINCLUDEDIR = /usr/local/Cellar/postgresql/9.1.2/include
INCLUDEDIR-SERVER = /usr/local/Cellar/postgresql/9.1.2/include/server
LIBDIR = /usr/local/Cellar/postgresql/9.1.2/lib
PKGLIBDIR = /usr/local/Cellar/postgresql/9.1.2/lib
LOCALEDIR = /usr/local/Cellar/postgresql/9.1.2/share/locale
MANDIR = /usr/local/Cellar/postgresql/9.1.2/share/man
SHAREDIR = /usr/local/Cellar/postgresql/9.1.2/share/postgresql
SYSCONFDIR = /usr/local/Cellar/postgresql/9.1.2/etc
PGXS = /usr/local/Cellar/postgresql/9.1.2/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--disable-debug' '--prefix=/usr/local/Cellar/postgresql/9.1.2' '--enable-thread-safety' '--with-bonjour' '--with-gssapi' '--with-krb5' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-python' '--with-perl' '--with-ossp-uuid' '--datadir=/usr/local/Cellar/postgresql/9.1.2/share/postgresql' '--docdir=/usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql' 'ARCHFLAGS='''-arch x86_64'''' 'CC=/usr/bin/llvm-gcc' 'CFLAGS=-O3 -w -pipe -march=core2 -msse4.1 -I/opt/local/include/ossp' 'LDFLAGS=-L/usr/local/Cellar/readline/6.2.2/lib -L/opt/local/lib' 'LIBS=-luuid' 'CPPFLAGS=-I/usr/local/Cellar/readline/6.2.2/include -I/usr/include/libxml2'
CC = /usr/bin/llvm-gcc
CPPFLAGS = -I/usr/local/Cellar/readline/6.2.2/include -I/usr/include/libxml2 -I/opt/local/include/libxml2
CFLAGS = -O3 -w -pipe -march=core2 -msse4.1 -I/opt/local/include/ossp -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL = 
LDFLAGS = -L/usr/local/Cellar/readline/6.2.2/lib -L/opt/local/lib -L/opt/local/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm -luuid
VERSION = PostgreSQL 9.1.2

我尝试了所有 export rvm_archflags="-arch x86_64" 类型的解决方案,但似乎没有任何区别。

任何想法我应该从哪里开始?

【问题讨论】:

自制程序错误是什么?当你做brew info postgres时它说什么? 或者你的意思是它在 brew 下正确安装但仍然不会构建 gem 扩展? 【参考方案1】:

我不熟悉 Brew,但看起来您调用的 pg_config 不是用于配置 pg 的那个。

所以,请尝试在路径中包含 /usr/local/Cellar/postgresql/9.1.2/bin(期望有 pg_config)并重试。

实际上,输出显示“使用 /usr/local/bin/pg_config 中的配置值” 它应该是 Brew 路径中的 pg_config。我猜它在 /usr/local/Cellar/postgresql/9.1.2/bin 中。

【讨论】:

【参考方案2】:

这可能会有所帮助:https://plus.google.com/104769575749979987265/posts/CVdrNMZYU9R

无论如何它都适用于 Linux。

【讨论】:

以上是关于pg gem 安装错误 - lion osx、bundler 和 rvm的主要内容,如果未能解决你的问题,请参考以下文章

安装 pg gem;错误:无法构建 gem 原生扩展

在 osx 上安装 pg gem 时出错

Rails:在 OS X 上安装 PG gem - 无法构建本机扩展

rails 4.2.0:无法在 ubuntu 14.04 上安装 pg gem

在 OSX 上安装 rmagick gem 时出错 - 错误:无法构建 gem 原生扩展

无法使用 Mavericks 在我的 Mac 上安装 PG gem