5

在花了几个小时试图弄清楚它为什么不起作用之后,我终于设法安装了“pg”gem ......

最后我进入了sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 0.12.2 -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config它就像一个魅力。但是现在我在尝试 bundler 时仍然遇到同样的错误 - 所以我想我并没有真正解决问题?无论如何,这里bundle install是说:

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

            /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.2/bin/pg_config
    Using config values from /usr/pgsql-9.2/bin/pg_config
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for PQconnectdb() in -lpq... yes
    checking for PQconnectionUsedPassword()... yes
    checking for PQisthreadsafe()... yes
    checking for PQprepare()... yes
    checking for PQexecParams()... yes
    checking for PQescapeString()... yes
    checking for PQescapeStringConn()... yes
    checking for PQgetCancel()... yes
    checking for lo_create()... yes
    checking for pg_encoding_to_char()... yes
    checking for PQsetClientEncoding()... yes
    checking for rb_encdb_alias()... yes
    checking for rb_enc_alias()... yes
    checking for struct pgNotify.extra in libpq-fe.h... yes
    checking for unistd.h... yes
    checking for ruby/st.h... yes
    creating extconf.h
    creating Makefile

make
    compiling compat.c
    compiling pg.c
    pg.c: In function ‘pgconn_wait_for_notify’:
    pg.c:2117: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c: In function ‘pgconn_block’:
    pg.c:2592: warning: format not a string literal and no format arguments
    pg.c:2598: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c:2607: warning: format not a string literal and no format arguments
    linking shared-object pg_ext.bundle
    ld: warning: directory not found for option '-L-Wl,-undefined,dynamic_lookup'
    Undefined symbols for architecture x86_64:

....

    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    make: *** [pg_ext.bundle] Error 1

我认为问题在于捆绑器尝试使用来自另一个 postresql 安装(我已删除)的 pg_config 安装 gem。有什么方法可以确保捆绑器使用正确的路径?

4

2 回答 2

10

我被困在我的捆绑安装上 3 天。尝试了一切,比如添加 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

我能够看到在这个命令之后安装了 pg gem,但它仍然没有从 bundle install 安装,这很痛苦,因为我不知道在 Gemfile 中写什么,除了 gem 'pg'

最终对我有用的是发现我的 pg_config 在 /Library/PostgreSQL/9.3/bin/pg_config 中,默认情况下 Gemfile 包安装在 /usr/local/bin/pg_config

我刚刚运行了以下命令,神奇的事情发生了。捆绑配置 build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

于 2014-12-26T07:05:55.257 回答
4

一些修正。对于那些使用自制软件安装了 postgres 的人。

1)在您的 ~/.bash_profile 中写入以下行

出口 ARCHFLAGS="-arch x86_64"

2)重启控制台

3)执行以下命令

bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config (这必须是您的 pg 配置地址,可能因 postgres 的版本而异)

4)通过运行此命令在本地安装一次pg

sudo env ARCHFLAGS="-arch x86_64" gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

5)捆绑安装

于 2015-09-21T19:06:51.643 回答