4

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!

6
  • Not sure but found one article on stackoverflow. Hope it will help you stackoverflow.com/questions/9668753/rails-3-cant-install-pg-gem Commented Oct 14, 2015 at 6:19
  • 1
    RVM overloads the cd command in your shell so that when you switch to another project it will automatically switch to the correct ruby and/or gemset. Try running rvm list and rvm gemset list and check that you have the same ruby and gemset as before. If you are using gemsets you might want to just use bundler instead: rakeroutes.com/blog/how-to-use-bundler-instead-of-rvm-gemsets Commented Oct 14, 2015 at 6:22
  • thanks! that did not work, but thank you for taking your time to answer. Commented Oct 14, 2015 at 15:43
  • 1
    checking for pg_config... yes <- no, it's a different issue. Commented Oct 14, 2015 at 16:39
  • 1
    The first comment used to be an answer, I pointed out that it's about a different issue. Now it has been converted to a comment and moved here, causing a bit of confusion. Commented Oct 15, 2015 at 7:03

3 Answers 3

2

I had the same problem and fixed it by:

1) $ brew update

2) $ brew install postgres

2) $ gem install pg

Sign up to request clarification or add additional context in comments.

Comments

1

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. 

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.