While building a rails app, suddenly got a message that my rails gem was gone, so I re-installed rails completely. Then got this:
An error occurred while installing pg (0.18.2), and Bundler cannot continue. Make sure that gem install pg -v '0.18.2'
succeeds before bundling.
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.
When I open the mkmf.log file, I get this:
/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.
How do I fix this? Thanks!
I had the same problem and fixed it by:
1) $ brew update
2) $ brew install postgres
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.
It looks like the problem was in XCode command tools that needed to be updated. I updated the command tools and then re-installed postgres with homebrew as well as reinstalled the pg gem. Worked like a charm. Works on El Capitan now also.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.