【问题标题】:Error installing pg gem -- extconf.rb failed安装 pg gem 时出错——extconf.rb 失败
【发布时间】:2015-10-14 06:11:11
【问题描述】:

在构建 rails 应用程序时,突然收到一条消息,说我的 rails gem 不见了,所以我完全重新安装了 rails。然后得到了这个:

安装 pg (0.18.2) 时出错,Bundler 无法继续。 在捆绑之前确保gem install pg -v '0.18.2' 成功。

但是运行命令会得到这个:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r    ./siteconf20151014-55380-170ndlh.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/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... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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.

我不确定这是否相关,但在它开始发生的时候,我的捆绑器停止安装没有 sudo 的 gem,而我以前从未需要过。

当我打开 mkmf.log 文件时,我得到了这个:

 /usr/local/Cellar/postgresql/9.4.5/include/libpq-fe.h:250:1: note:   'PQconnectdb' declared here
 extern PGconn *PQconnectdb(const char *conninfo);
 ^
 1 error generated.
 checked program was:
 /* begin */
 1: #include "ruby.h"
 2: 
 3: #include <libpq-fe.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int t(void) { PQconnectdb(); return 0; }
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
/* end */

--------------------

(日志较长,但这是它的尾部有错误)。

我试过gem install pg — –with-pg-lib=/usr/lib,还是不行。

我该如何解决这个问题?谢谢!

【问题讨论】:

  • 不确定,但在 stackoverflow 上找到了一篇文章。希望对你有帮助stackoverflow.com/questions/9668753/rails-3-cant-install-pg-gem
  • RVM 会在你的 shell 中重载 cd 命令,这样当你切换到另一个项目时,它会自动切换到正确的 ruby​​ 和/或 gemset。尝试运行 rvm listrvm gemset list 并检查您是否拥有与以前相同的 ruby​​ 和 gemset。如果您使用 gemsets,您可能只想使用 bundler:rakeroutes.com/blog/how-to-use-bundler-instead-of-rvm-gemsets
  • 谢谢!这不起作用,但感谢您抽出宝贵时间回答。
  • checking for pg_config... yes
  • 第一个评论曾经是一个答案,我指出这是一个不同的问题。现在已经转成评论移到这里,造成了一些混乱。

标签: ruby-on-rails macos postgresql rvm bundler


【解决方案1】:

我遇到了同样的问题并通过以下方式解决了它:

1) $ brew update

2) $ brew install postgres

2)$ gem install pg

【讨论】:

    【解决方案2】:

    只是发布我自己的答案,因为结果出乎意料,我尝试了在 Stackoverflow 上找到的所有方法来解决它,但无济于事。

    看起来问题出在需要更新的 XCode 命令工具中。我更新了命令工具,然后用自制软件重新安装了 postgres,并重新安装了 pg gem。像魅力一样工作。现在也适用于 El Capitan。

    【讨论】:

      【解决方案3】:

      对我来说是this answer 解决了:

      Installing unf_ext 0.0.7.6 with native extensions
      Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
      
          current directory: /Users/luka/.rvm/gems/ruby-2.5.1/gems/unf_ext-0.0.7.6/ext/unf_ext
      /Users/luka/.rvm/rubies/ruby-2.5.1/bin/ruby -r ./siteconf20200122-42541-136wsjb.rb
      extconf.rb
      checking for -lstdc++... *** 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.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-16
        • 1970-01-01
        • 2015-10-08
        • 2013-05-21
        • 1970-01-01
        • 2016-10-04
        • 2014-09-21
        相关资源
        最近更新 更多