3

I have been trying for some time now to get my Rails development environment back up since I upgraded from Lion to Mountain Lion. The problem is specifically installing the pg-0.14.0 (postgresql) gem.

I have tried the instructions on this post but with no luck. I have tried uninstalling Postgres with Homebrew and then reinstalling it. Nothing is working. If I try to install this gem I recieve this error:

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/1.8/usr/bin/ruby 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.

Where can I find mkmf.log? Can anyone give me a suggestion on how to install the pg gem again?

update I was able to locate my mkmf.log file using :

find / -name mkmf.log 2>/dev/null

There are several failed xcrun calls like the one below:

have_library: checking for PQconnectdb() in -llibpq... -------------------- no

"xcrun cc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/postgresql/9.1.4/include -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -L. -arch i386 -arch x86_64 -L/usr/local/Cellar/postgresql/9.1.4/lib -lruby -llibpq -lpthread -ldl -lobjc " ld: library not found for -llibpq clang: error: linker command failed with exit code 1 (use -v to see invocation)

Why am I getting errors when running xcrun? Has anyone seen this?

Thanks!

Community
  • 1
  • 1
Nick
  • 19,198
  • 51
  • 185
  • 312

4 Answers4

2

The error says it right there:

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)

It can't find libpq, or its tests that try to compile a test program and link to it are failing. Since it's finding /usr/local/bin/pg_config it should know where the Pg libraries and headers are, so the problem is probably an error in the test compile.

To learn more you will need to examine mkmf.log. Run

find . -name mkmf.log

from within the directory you ran the gem install command, that'll probably locate it. Update your post with its contents.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Thanks for the reply. Running gem install pg -v '0.14.0' installs the gem without error. However running bundle install results in the error I posted. When I attempt to find the mkmf.log file in the same directory with I have run both of the above mentioned commands.. it is not found. – Nick Aug 08 '12 at 04:54
  • @Nick I'm afraid you're outside my Ruby + Mac OS X knowledge then. Do some digging to see if the bundle command is running in a temporary compile directory somewhere. If you're willing to wait, run `find / -name mkmf.log 2>/dev/null` to search your whole system, suppressing permissions errors. – Craig Ringer Aug 08 '12 at 05:01
2

I got this resolved finally. I used RVM to uninstall ruby and re-install ruby version 1.9.3. This allowed me to run 'bundle install' without a problem. I checked that all gems where loaded (gem list). However my rails application could not locate the postgres socket file at this point. The same problem is detailed here. Rather than locating the postgresql.conf file, changing permissions on it, and editing it I just uninstalled my current version of Postgres and downloaded the latest One-Click installer from PostGres. When I ran the installer again it detected the other PostGres installation and updated it. This updated the configurations for me and all is well again.

I hope this might help some other poor rails dev upgrading to Mountain Lion :)

Community
  • 1
  • 1
Nick
  • 19,198
  • 51
  • 185
  • 312
0

I've struggled a few hours with this too and couldn't find anything working in my setup.

I ended up using postgres.app. This is a packaged version of Postgres released by the people at Heroku. They say it's "the easiest way to run postgreSQL on the Mac". Based on my experience, this is true!

Just drop it into you Applications folder and you're done! (I've just had to restart to free port 5432).

Side note: they also have released an application called Induction to manage and query your databases, but for the moment it is unusable in Mountain Lion.

Pierre
  • 8,368
  • 4
  • 34
  • 50
  • This didn't work for me. In fact it doesn't seem to do anything when I run it. Maybe because I have Postgresql installed already? – Nick Aug 09 '12 at 15:36
  • Do you have the small elephant in the menu bar? If so, click on it. What do you see? – Pierre Aug 09 '12 at 16:43
0

If you have Mountain Lion and XCODE 4.4.1 you don't have the command tool go and dowload from here https://developer.apple.com/downloads/index.action

Jean
  • 5,201
  • 11
  • 51
  • 87