5

我想为 Heroku 构建一个 Rails 3 应用程序。他们使用 Postgres 作为他们的数据库,所以我通过 MacPorts 安装了 postgres 9.0。现在我需要一个 postgres gem,并且一致认为出于性能原因你想要 pg gem。但是,当我尝试通过 rvm 下的 gem install 安装 pg 时遇到的错误让我完全感到困惑。

我非常明确地指定了所有 postgres 目录的位置,但仍然无法完成安装:

$ env ARCHFLAGS='-arch x86_64' gem install pg -- \
   --with-pg-config=/opt/local/var/db/postgresql90/defaultdb/postgresql.conf \
   --with-pg-include=/opt/local/include/postgresql90/ \
   --with-pg-lib=/opt/local/lib/postgresql90/

Using config values from /opt/local/var/db/postgresql90/defaultdb/postgresql.conf
*** 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/guy/.rvm/ruby-1.9.2-p136/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include=${pg-dir}/include
    --with-pg-lib=${pg-dir}/lib
    --with-pg-config
extconf.rb:24:in ``': Exec format error - /opt/local/var/db/postgresql90/defaultdb/postgresql.conf --includedir (Errno::ENOEXEC)
    from extconf.rb:24:in `<main>'

有人有什么想法吗?我很困惑。盖伊

4

2 回答 2

6

我认为你的问题就在这里:

--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/postgresql.conf

--with-pg-config交换机可能想知道脚本在哪里pg_config而不是在哪里postgresql.conf。你应该在pg_config下面的某个地方有一个脚本/opt/local/bin(可能),它应该产生一大堆这样的东西:

BINDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/bin
DOCDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/share/doc
HTMLDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/share/doc
INCLUDEDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/include
PKGINCLUDEDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/include
INCLUDEDIR-SERVER = /Users/mu/Developer/Cellar/postgresql/9.0.1/include/server
LIBDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/lib
PKGLIBDIR = /Users/mu/Developer/Cellar/postgresql/9.0.1/lib
...

当你运行它时。该pg_config脚本会告诉您(或询问的人)各种头文件和库在哪里以及需要哪些编译器标志。

“执行格式错误”错误消息是赠品。这听起来像是您正在尝试执行操作系统不知道如何执行的东西,我不希望 OSX 知道如何执行一些任意配置文件。

于 2011-06-30T07:06:57.127 回答
2

我使用的最简单的修复方法:将 /opt/local/lib/postgresql90/bin/ 添加到您的 $PATH。

假设你使用 bash shell,然后在 ~/.bashrc

PATH=/opt/local/lib/postgresql90/bin:$PATH

现在在 Gemfile 中有一个简单的行:

宝石'pg'

会工作的。

于 2011-06-30T11:15:12.037 回答