1

Here's the error I get when I run gem install pg:

ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20151004-5579-1t2l557.rb 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 ***

If I run brew install postgres I get:

Warning: postgresql-9.4.4 already installed

Likewise, gem list shows pg (0.18.3) and a simple gem -v pg gives:

2.4.4

Running sudo ARCHFLAGS="-arch x86_64" gem install pg returns:

Building native extensions.  This could take a while...
Successfully installed pg-0.18.3
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.3
Done installing documentation for pg after 4 seconds
1 gem installed

But bundle install throws up this error:

An error occurred while installing pg (0.18.3), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.3'` succeeds before bundling.

I'm seeing this in mkmf.log, which I think could be the biggest clue:

ld: warning: ignoring file /opt/local/lib/postgresql93/libpq.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/postgresql93/libpq.dylib
Undefined symbols for architecture i386:
  "_PQconnectdb", referenced from:
      _t in conftest-fc6c12.o
ld: symbol(s) not found for architecture i386

Which is strange given file /opt/local/lib/postgresql93/libpq.dylib returns x86_64, not i386:

/opt/local/lib/postgresql93/libpq.dylib: Mach-O 64-bit dynamically linked shared library x86_64

This didn't work either:

sudo env ARCHFLAGS="-arch i386 -arch x86_64" gem install pg
Sebastian
  • 3,548
  • 18
  • 60
  • 95
  • See if anything here helps: http://stackoverflow.com/questions/19625487/impossible-to-install-pg-gem-on-my-mac-with-mavericks – Brian Oct 04 '15 at 16:58
  • Thanks for your response. I've updated my question to include the outcomes of those solutions. – Sebastian Oct 04 '15 at 17:07

3 Answers3

2

It seems you're almost there, because sudo ARCHFLAGS="-arch x86_64" gem install pg works. Try setting ARCHFLAGS globally, so bundle also can see it:

$ export ARCHFLAGS="-arch x86_64"
$ bundle
Alexey Shein
  • 7,342
  • 1
  • 25
  • 38
1

I've been working through this issue since yesterday. I ended up uninstalling Postgres, homebrew, and starting from scratch. When trying to add the 'pg' gem to my Ruby on Rail project it kept failing. Digging through the output I kept seeing it try to link the i386 libraries. So I tried adding the flag:

--arch-flags='x86_64'

That didn't seem to have any impact.

Then I found one where it was set right after the 'sudo'. That seemed to do the trick.

THIS WORKED!!!!!!!!

sudo ARCHFLAGS="-arch x86_64" gem install pg -v '0.18.3' -- --with-pg-config=/usr/local/bin/pg_config --arch-flags='x86_64'

In the project I actually had to repeat the steps for some reason in the project directory. Then re-repeat them and upgrade to version 0.18.4.

After that I could run 'bundle' and everything was included correctly.

MudDawg
  • 11
  • 1
0

A couple of the answers here:

http://stackoverflow.com/questions/19625487/impossible-to-install-pg-gem-on-my-mac-with-mavericks

suggest specifying the postgresql configuration file when performing the gem install. It is older but might provide the way forward. Search for "Check you have pg_config in the installed brew", which explains how to find the correct filename.

Brian
  • 967
  • 7
  • 12