title: Error installing pg gem -- extconf.rb failed
body: <p>While building a rails app, suddenly got a message that my rails gem was gone, so I re-installed rails completely. Then got this:</p>
  
  <p>An error occurred while installing pg (0.18.2), and Bundler cannot continue.
  Make sure that <code>gem install pg -v '0.18.2'</code> succeeds before bundling.</p>
  
  <p>But running the command gets me this:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>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.</p>
  
  <p>When I open the mkmf.log file, I get this:</p>
  
  <pre><code> /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 &lt;libpq-fe.h&gt;
   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 &gt; 1000000) {
  11:     printf("%p", &amp;t);
  12:   }
  13: 
  14:   return 0;
  15: }
  /* end */
  
  --------------------
  </code></pre>
  
  <p>(the log is longer, but this is the tail part of it that has an error in it).</p>
  
  <p>I tried <code>gem install pg — –with-pg-lib=/usr/lib</code>, which did not work.</p>
  
  <p>How do I fix this? Thanks!</p>