[英]Error installing pg gem -- extconf.rb failed
While building a rails app, suddenly got a message that my rails gem was gone, so I re-installed rails completely.在构建 rails 应用程序时,突然收到消息说我的 rails gem 不见了,所以我完全重新安装了 rails。 Then got this:然后得到了这个:
An error occurred while installing pg (0.18.2), and Bundler cannot continue.安装 pg (0.18.2) 时出错,Bundler 无法继续。 Make sure that gem install pg -v '0.18.2'
succeeds before bundling.在捆绑之前确保gem install pg -v '0.18.2'
成功。
But running the command gets me this:但是运行命令让我得到这个:
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.
I am not sure if this is relevant, but around the time it started happening, my bundler stopped being able to install gem without sudo, which I never needed before.我不确定这是否相关,但在它开始发生的时候,我的捆绑器不再能够在没有 sudo 的情况下安装 gem,这是我以前从未需要的。
When I open the mkmf.log file, I get this:当我打开 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 */
--------------------
(the log is longer, but this is the tail part of it that has an error in it). (日志较长,但这是其中有错误的尾部部分)。
I tried gem install pg — –with-pg-lib=/usr/lib
, which did not work.我试过gem install pg — –with-pg-lib=/usr/lib
,但没有用。
How do I fix this?我该如何解决? Thanks!谢谢!
I had the same problem and fixed it by:我遇到了同样的问题并通过以下方式修复了它:
1) $ brew update
1) $ brew update
2) $ brew install postgres
2) $ brew install postgres
2) $ gem install pg
2) $ gem install pg
Just posting my own answer because the solution turned out rather unexpected, and I tried every single way to solve it I had found on Stackoverflow to no avail.只是发布我自己的答案,因为解决方案出乎意料,我尝试了在 Stackoverflow 上找到的所有方法来解决它,但无济于事。
It looks like the problem was in XCode command tools that needed to be updated.看起来问题出在需要更新的 XCode 命令工具中。 I updated the command tools and then re-installed postgres with homebrew as well as reinstalled the pg gem.我更新了命令工具,然后用自制软件重新安装了 postgres,并重新安装了 pg gem。 Worked like a charm.像魅力一样工作。 Works on El Capitan now also.现在也适用于 El Capitan。
For me it was this answer that solved the :对我来说,正是这个答案解决了:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.