title: Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5)
body: <p>I just upgraded to Rails 3 and had a bit of a mess with MacPorts, gems and databases to sort out. I threw out all the gems and installed them fresh. Everything seems to be OK except for the requirement of the pg gem.</p>
  
  <p>After creating a new Rails 3 project, prepared for PostgreSQL, the server would not start, complaining about the missing pg gem. Doing <code>bundle install</code>, it chugged along for a while and, of course, fails on the pg gem.</p>
  
  <pre><code>Installing pg (0.10.0) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
  
  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
  mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
  
  
  Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
  Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
      from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
      from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
      from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/source.rb:95:in `install'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:55:in `run'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in `run'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in `install'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in `install'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `send'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `run'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start'
      from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/bin/bundle:13
      from /usr/bin/bundle:19:in `load'
      from /usr/bin/bundle:19
  </code></pre>
  
  <p>The most common suggestion I have found on forums and blogs is to (re)install the XCode developer tools. They were already there, but I reinstalled them anyway, with no better outcome than the above.</p>
  
  <p><code>which ruby</code> says <code>/usr/bin/ruby</code>, and <code>ruby -v</code> says <code>ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]</code>, if there's any clue there.</p>
  
  <p>Pointers are welcome. Any missing information that would help figuring this out, I'll gladly and promptly provide!</p>
  
  <hr>
  
  <p>I downloaded XCode since the DVD version is said to be broken and things went better for a while. <code>bundle install</code> started talking about "archflags" instead, so I did: </p>
  
  <pre><code>sudo env ARCHFLAGS="-arch i386" bundle install
  </code></pre>
  
  <p>and things seemed to go fine, until starting Rails barfed, saying:  </p>
  
  <pre><code>/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found.  Did find: (LoadError)
      /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle
  </code></pre>
  
  <p>Grappling for anything, I tried  <code>bundle install</code> with archflags set to <code>-arch x86_64</code>, but it didn't go well:</p>
  
  <pre><code>*** Your PostgreSQL installation doesn't seem to have an architecture in common with the running ruby interpreter ([] vs. ["x86_64"])
  I'll continue anyway, but if it fails, try setting ARCHFLAGS.
  [...]
  Can't find the PostgreSQL client library (libpq)
  *** extconf.rb failed ***
  </code></pre>
  
  <p>Is libpq something I now have to supply a path to via some flags? Or am I completely out to lunch?</p>