安装pg gem出现问题

8
尝试安装pg gem时出现错误。
我使用的是rbenv/ruby-build构建的Ruby 1.9.3-p125。我使用一键安装程序安装了PostgreSQL。我能够通过pgAdmin连接到数据库。但目前我已经没什么头绪了。
% gem install pg                                                                                                                                                                                                      ~
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /Users/sandropadin/.rbenv/versions/1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.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 pg_char_to_encoding()... 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 pg.c
compiling pg_connection.c
pg_connection.c: In function ‘pgconn_wait_for_notify’:
pg_connection.c:1986: warning: ‘rb_thread_select’ is deprecated (declared at /Users/sandropadin/.rbenv/versions/1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379)
pg_connection.c: In function ‘pgconn_block’:
pg_connection.c:2512: warning: ‘rb_thread_select’ is deprecated (declared at /Users/sandropadin/.rbenv/versions/1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379)
compiling pg_result.c
linking shared-object pg_ext.bundle
ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file for architecture x86_64
collect2: ld returned 1 exit status
make: *** [pg_ext.bundle] Error 1


Gem files will remain installed in /Users/sandropadin/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pg-0.13.2 for inspection.
Results logged to /Users/sandropadin/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pg-0.13.2/ext/gem_make.out

2
你从哪里获取了你的libssl?听起来你可能正在尝试混合32位和64位二进制文件。 - mu is too short
我认为只需使用 brew install openssl - Sandro
我认为你关于混合两者的想法是正确的,但我不知道是否可能或如何强制Homebrew将openssl构建为64位。 - Sandro
1个回答

14

不确定以下哪个步骤最终解决了这个问题。但是,正如mu is too short所提到的那样,问题在于32位和64位二进制文件混合使用。

  • 第一步,我安装了 PostgreSQL的64位版本
  • 第二步,我卸载了任何旧的Homebrew OpenSSL安装

    $ brew uninstall openssl

  • 第三步,我使用Homebrew安装了64位版本的OpenSSL

    $ brew install --64-bit openssl

  • 最后,在安装pg gem时,我将LDFLAGS更改为指向64位版本的OpenSSL

    $ gem install pg -- --with-ldflags='-L/usr/local/Cellar/openssl/0.9.8s'


1
我必须说,我一直在努力让 pg gem 在我的 Lion 上编译大约6个月。现在有了这个答案,我能够像冠军一样运行 Rails 3.2 + PostgreSQL。谢谢! - Chris Peters
1
这对我在Mountain Lion上的ruby 1.9.3p194(2012-04-20修订版35410)[x86_64-darwin12.0.0]有效。我使用了brew install postgresql,并且之前没有安装openssl,所以只需执行brew install --64-bit openssl,然后使用它提供的LDFLAGS。 - thugsb
工作得很好,除了openssl的版本已经更新(现在是1.0.1c)。用户需要cd /usr/local/Cellar/openssl/并运行“ls”以查看其版本号。 - Josh Crews

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接