ruby-on-railsrubymakefilebundleosx-mountain-lion

Could not create Makefile for some reason


I can't install the pg gem when I run bundle, or when I try to install it separately. The error I get is: "could not create Makefile." I'm running Mountain Lion, have Xcode installed, and have command line tools installed. I also have Postregsql installed via homebrew.

I believe the error is because I can't create the makefile, which has surfaced as the error preventing me from doing other things.

The full error I get is below.

This error happens during the bundle. The other gems are installed fine, or are marked as using, then this error terminates the bundle while installing pg (0.14.1) with native extensions

Gem::Installer::ExtensionBuildError: 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/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.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib


Gem files will remain installed in /Users/ericavirtue/.bundler/tmp/75812/gems/pg-0.14.1 for inspection.
Results logged to /Users/ericavirtue/.bundler/tmp/75812/gems/pg-0.14.1/ext/gem_make.out
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.

I'm really at a loss for what to do here. I've been working on this for two days.

EDIT:

So when trying to find the path to implement the solution Christian Rapp suggested I found this recommendation: sudo env ARCHFLAGS="-arch x86_64" gem install pg which worked to install pg. Unfortunately I'm getting errors when I try to run rails s, rake db:create:all, or rake db:migrate. I'll create a separate question to trace those problems down ...


Solution

  • I am not using homebrew on MacOS but where does it install libpq? MacPorts is using /opt and your configure script does not know anything about this. The error messages is quite informative just provide the path with something like

    gem install pg -- --with-libpqlib=/opt/...

    May be you have to use another flag to provide the necessary Informations