安装pg gem时出错 - extconf.rb失败

时间:2015-10-14 06:11:11

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

在构建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,但没有效果。

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

3 个答案:

答案 0 :(得分:2)

我遇到了同样的问题并通过以下方式修复:

1)with t as (<your query here>) select min(term_start), max(term_end), block, quantity from (select t.*, (row_number() over (partition by block order by position) - row_number() over (partition by quantity, block order by position) ) as grp from t ) t group by quantity, grp, block;

2)$ brew update

2)$ brew install postgres

答案 1 :(得分:0)

只是发布我自己的答案,因为解决方案结果出乎意料,我尝试了解决它的每一种方法,我在Stackoverflow上找不到它。

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

答案 2 :(得分:0)

对我来说,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.