0

Used a time machine backup to sync files from my macbook running Leopard to my macbook pro running Lion. After having trouble pushing to heroku due to the fact that I was running sqlite3, I went down a rabbit hole in trying to get a pg gem installed.

gem install pg

yields:

        /Users/taylorjackson/.rvm/rubies/ruby-1.9.2-p136/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 ***
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'm a Unix noob and fear there's something deeply wrong with the file structure that was created by time machine in mashing up 32 bit leopard with 64 bit lion. Steps I've taken so far.

Reinstalled XCode

Xcode 4.3.3
Build version 4E3002

Installed command line tools in XCode from preferences.

updated to rvm 1.14.6 (master) with

rvm get head

Banged head against wall trying to install postgre locally with macports. uninstalled macports and installed homebrew

Followed recs from

brew doctor

then

brew install postgresql

ran into python issues and followed advice to install w/o python

brew install --no-python postgresql

seemed to get a clean install of postgresql, but my output from

gem install pg 

is still:

        /Users/taylorjackson/.rvm/rubies/ruby-1.9.2-p136/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 ***
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.

Also tried

bundle install

and

bundle config build.pg --with-pg-config=/users/taylorjackson/postgresql/bin/pg_config
bundle install

with the same results My productivity for the last 7 hours has dropped to nothing. Can't find the relevant mkmf.log file. Any other ideas?

EDIT:

found mkmf.log. Here are relevant contents:

def have_devel?
  unless defined? $have_devel
    $have_devel = true
    $have_devel = try_link(MAIN_DOES_NOTHING)
  end
  $have_devel
end

def try_do(src, command, &b)
  unless have_devel?
    raise <<MSG
The complier failed to generate an executable file.
You have to install development tools first.
MSG
  end
  begin
    src = create_tmpsrc(src, &b)
    xsystem(command)
  ensure
    log_src(src)
    rm_rf 'conftest.dSYM'
  end
end
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
TronSawyer
  • 46
  • 1
  • 6
  • There are lots of near identical questions on a search for "gem install Lion". Did you search before posting, and if so, what about the existing answer didn't help? – Craig Ringer Jul 23 '12 at 23:45
  • I spent almost 4 hours stepping through relevant threads, (hence my long initial post, which comes largely from SE advice). It seems like there are lots of relevant weird contingencies of file structure - all machine dependent. In my case, somehow my install location for postgresql created a new local user (though I didn't change any default locations - installed to /usr /root maybe??), and led the gem install to look for local pg install in the wrong spot. Reset and delete user (+ everything else mentioned in original post) set things straight. – TronSawyer Jul 24 '12 at 15:22
  • Ah, thanks. I only asked 'cos I've seen a real surge of v.similar posts re the pg jem on ruby on OSX lion lately. Helps if you link to related posts, not least because it'll help other people who find your question late.r – Craig Ringer Jul 25 '12 at 00:30

2 Answers2

1

The file you found was mkmf.rb, not mkmf.log. The mkmf.log will look something like this at the beginning:

find_executable: checking for pg_config... -------------------- yes

--------------------

find_header: checking for libpq-fe.h... -------------------- yes
"/usr/bin/gcc-4.2 -o conftest -I/Users/mgranger/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin11.3.0 -I/Users/mgranger/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/mgranger/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -I/Users/mgranger/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/include  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe conftest.c  -L. -L/Users/mgranger/.rvm/rubies/ruby-1.9.3-p194/lib -L/Users/mgranger/.rvm/usr/lib -L. -L/usr/local/lib -L/usr/lib     -lruby.1.9.1  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

You can find it in the 'ext' directory in the unpacked gem. Under bash, this works for me:

less $(dirname $(gem which pg))/../ext/mkmf.log

Under OSX, failing on the first header is almost always a sign of some problem with your compiler setup, especially if it found your pg_config (and it looks like yours did). Look to see that the 'gcc' at the beginning of the command in quotes actually exists on your machine. In my case that's /usr/bin/gcc-4.2. If that's missing, you'll need to fix that before any extension will install correctly from source.

If, on the other hand, your gcc does exist, attach the mkmf.log file, which will usually contain the clues necessary to point you in the right direction.

Michael Granger
  • 1,358
  • 9
  • 14
0

Restarted, and noticed that somehow PostgreSQL had been added as a user(!). Deleted the user, added gem 'pg' to the gemfile and bundle installed, and the whole thing went smoothly. Not sure what bizarreness in the installation process could have caused that to happen. I didn't change any defaults in the installation - but my guess is a problem with using an out of date version of macports.

For those in a similar situation, I'd recommend 1) never switch OS's with a time machine backup. 2) Clean install xcode, xcode developer tools (from xcode preferences menu), and homebrew. 3) force update rvm 4) install postgresql locally with brew install postgresql. 5) Restart and try bundle installing the pg gem again. I did a lot of stuff, but I think those are the steps that I think worked.

TronSawyer
  • 46
  • 1
  • 6
  • FYI,. usually PostgreSQL runs under its own user account. Delete that and you might cause issues running it on the default configuration. – Chris Travers Sep 27 '12 at 01:54