Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find the PostgreSQL client library (libpq)

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg

Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...

WORKED!


I tried the top-rated answer here:

env ARCHFLAGS="-arch x86_64" gem install pg

But when I tried running bundle install again, it had the same error. Then I tried the entire bundle install with ARCHFLAGS like so:

ARCHFLAGS="-arch x86_64" bundle install

Worked for me! Make sure to replace x86_64 with i386 depending on what architecture you have.


I was just having this problem when using the EnterpiseDB .dmg. If that's the same think you used, I got it to work by specifying the right architecture:

sudo env ARCHFLAGS="-arch i386" gem install pg

There are some tutorials on the web that said to specify a different architecture (like "-arch x86_64" for people who used MacPorts) but it wasn't working for me because I used the single file install.


If using Yosemite:

brew install postgres

Then:

ARCHFLAGS="-arch x86_64" gem install pg

And (optional) finally, if you want to launch autovacuum...

postgres -D /usr/local/var/postgres

Maybe you can try this one:

ARCHFLAGS="-arch i386 -arch x86_64" gem install pg

To know the architecture of your library you can use

file /usr/local/lib/libpq.dylib 

which gave just 1 architecture in my case (installed via homebrew):

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

Solution: reinstalled PostgreSQL with Homebrew.


Fake out gem by prefixing the appropriate environment variables. If you were installing from MacPorts, you should be able to walk through the following procedure:

% /opt/local/lib/postgresql91/bin/pg_config
BINDIR = /opt/local/lib/postgresql91/bin
DOCDIR = /opt/local/share/doc/postgresql
HTMLDIR = /opt/local/share/doc/postgresql
INCLUDEDIR = /opt/local/include/postgresql91
PKGINCLUDEDIR = /opt/local/include/postgresql91
INCLUDEDIR-SERVER = /opt/local/include/postgresql91/server
LIBDIR = /opt/local/lib/postgresql91
PKGLIBDIR = /opt/local/lib/postgresql91
LOCALEDIR = /opt/local/share/locale
MANDIR = /opt/local/share/man
SHAREDIR = /opt/local/share/postgresql91
SYSCONFDIR = /opt/local/etc/postgresql91
PGXS = /opt/local/lib/postgresql91/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/opt/local' '--sysconfdir=/opt/local/etc/postgresql91' '--bindir=/opt/local/lib/postgresql91/bin' '--libdir=/opt/local/lib/postgresql91' '--includedir=/opt/local/include/postgresql91' '--datadir=/opt/local/share/postgresql91' '--mandir=/opt/local/share/man' '--with-includes=/opt/local/include' '--with-libraries=/opt/local/lib' '--with-openssl' '--with-bonjour' '--with-readline' '--with-zlib' '--with-libxml' '--with-libxslt' '--enable-thread-safety' '--enable-integer-datetimes' '--with-ossp-uuid' 'CC=/usr/bin/gcc-4.2' 'CFLAGS=-pipe -O2 -arch x86_64' 'LDFLAGS=-L/opt/local/lib -arch x86_64' 'CPPFLAGS=-I/opt/local/include -I/opt/local/include/ossp'
CC = /usr/bin/gcc-4.2
CPPFLAGS = -I/opt/local/include -I/opt/local/include/ossp -I/opt/local/include/libxml2 -I/opt/local/include
CFLAGS = -pipe -O2 -arch x86_64 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL = 
LDFLAGS = -L/opt/local/lib -arch x86_64 -L/opt/local/lib -L/opt/local/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lz -lreadline -lm 
VERSION = PostgreSQL 9.1beta1

From there, pull out the LIBDIR, INCLUDEDIR, CPPFLAGS, LIBS and LDFLAGS (the one that I think will get you running is LIBDIR, however). Then you'd run:

setenv PATH /opt/local/lib/postgresql91/bin:${PATH}
sudo env LDFLAGS=-L`pg_config --libdir` CPPFLAGS=`pg_config --cppflags` gem install pg

That should do it for you. Let me know if it doesn't.