I have Mountain Lion on my new machine. (What a horrible release.) I innocently decided to upgrade my Postgres installation to 9.2.2. I had a lot of trouble getting the Ruby pg gem to build. I found no single source that solved the problem, so I thought I’d post the solution.
The symptom is this spewage:
ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/marick/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/local/bin/pg_config checking for libpq-fe.h... *** extconf.rb failed ***
Note: if the “checking for pg_config” line fails, you have a different problem. Either you need to set PGDATA correctly, or make sure that the `pg_config` command is in your $PATH. A number of pages out there on the web explain what’s going on.
If you look at the `mkmf.log` file, you’ll see that (for some reason) the installer is trying to use `/usr/bin/gcc-4.2`. That doesn’t exist, so:
sudo ln -s /Developer/usr/bin/gcc /usr/bin/gcc-4.2
That still fails because the program you’re compiling innocently tries to include `<stdio.h>` (etc.) Unlike Unix systems since the beginning of time, there is no `stdio.h` in `/usr/include`. To populate /usr/include you have to start Xcode (version 4.X), go to Preferences, pick the “Downloads” tab, and install the Command Line Tools.
Thanks to Tim Burks on Twitter for this piece of the puzzle.