Rails pg gem,安装pg时出现错误

3
我将尝试把我的Rails应用部署到Heroku,但在安装pg gem时遇到了问题。有人告诉我要将Gemfile中的"gem 'sqlite3'"替换为以下内容:
group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
  gem 'rails_stdout_logging' 
end

然后执行 bundle install。我收到了以下错误消息:

...
Using coffee-rails (3.2.2) 
Using jquery-rails (3.0.4) 
Installing pg (0.17.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
    /usr/local/rvm/rubies/ruby-1.9.3-p392/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 PQescapeLiteral()... yes
checking for PQescapeIdentifier()... 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 PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... no
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... yes
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
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 gvl_wrappers.c
compiling pg.c
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.1/ext/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

所以,我尝试执行gem install pg -v '0.17.1'。我收到了这个错误信息:
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p392/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 PQescapeLiteral()... yes
checking for PQescapeIdentifier()... 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 PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... no
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... yes
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
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 gvl_wrappers.c
compiling pg.c
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1

我已阅读这些帖子并尝试了其中给出的解决方案,但它们都无法正常工作:

如果你想知道,我正在使用 Mac OS X 10.8.5。

3个回答

5
在控制台上运行以下命令...
sudo apt-get install libpq-dev


gem install pg

愉快的编码...


1
我猜您的系统中没有安装Postgres。您可以通过homebrew/macports安装postgresql,或者使用以下命令禁用production gems的安装:
bundle install --without production

0
问题出在你的系统中缺少PostgreSQL客户端。
请在终端上运行以下命令。
sudo apt-get install postgresql-client libpq5 libpq-dev

现在将这个 gem 添加到你的 Gemfile 中

gem 'pg'

并且运行这个

bundle install

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