IT

PostgreSQL 클라이언트 라이브러리를 찾을 수 없습니다 (libpq)

lottoking 2020. 6. 14. 10:10
반응형

PostgreSQL 클라이언트 라이브러리를 찾을 수 없습니다 (libpq)


Mac OS X 10.6에 PostgreSQL for Rails를 설치하려고합니다. 먼저 MacPorts 설치를 시도했지만 제대로 작동하지 않아 원 클릭 DMG 설치를 수행했습니다. 작동하는 것 같았습니다.

PostgreSQL 개발 패키지를 설치해야한다고 생각하지만 OS X에서이를 수행하는 방법을 모릅니다.

내가하려고 할 때 얻는 것은 다음과 같습니다 sudo gem install pg.

$ sudo gem install pg
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 /Library/PostgreSQL/8.3/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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 /Library/Ruby/Gems/1.8/gems/pg-0.11.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.11.0/ext/gem_make.out

$ 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...

일했다!


나는 여기서 최고 등급의 답변을 시도했다.

env ARCHFLAGS="-arch x86_64" gem install pg

그러나 번들 설치를 다시 시도했을 때 동일한 오류가 발생했습니다. 그런 다음 ARCHFLAGS를 사용하여 전체 번들 설치를 시도했습니다.

ARCHFLAGS="-arch x86_64" bundle install

나를 위해 일했다! 사용중인 아키텍처에 따라 x86_64를 i386으로 바꾸십시오.


EnterpiseDB .dmg를 사용할 때이 문제가 발생했습니다. 그것이 당신이 사용한 것과 같은 생각이라면, 올바른 아키텍처를 지정하여 작동하도록했습니다.

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.


The problem we had was pretty weird.

ruby -v # was ok (rbenv)
gem -v # was ok (rbenv)

but when we did a bundle install in fact, bundler wasn't installed for the version of ruby that was installed by rbenv, so, when we typed bundle install, it used the bundler of the system.

So before running bundle install, be sure that you have installed bundler by running

gem install bundler

I don't think you need the postgres development files, everything you need should have been included with your installer. It's more likely that the path they're installed to isn't in your environment path and therefore gem can't find them when it tries to compile pg.

You shouldn't have to run gem install pg as root, in fact if you do it's likely your PATH (root's PATH if run w/ sudo) won't contain the necessary info.

The following usually works for me:

# Might be different depending on where your installer installed postgres 8.3
export PATH=$PATH:/Library/PostgreSQL/8.3/include/
export ARCHFLAGS='-arch x86_64'
gem install pg

This is what finally did it for me (combination of multiple solutions provided before along with other posts):

$ sudo env ARCHFLAGS="-arch x86_64" gem install pg -- with-pg-include=/Library/PostgreSQL/9.6/include/


The ARCHFLAGS answer that others have proposed will not work if you somehow ended up with a 64-bit version of postgres (which homebrew will install) and a 32-bit version of ruby. For some reason rbenv insists on building ruby 1.9.2-p290 as 32-bit for me, which makes it impossible to link against 64-bit postgres.

Check the architecture of your ruby binary with

file `which ruby`

or if using rbenv

file `rbenv which ruby`

And compare against your postgres:

file `which postgres`

If there's a mis-match you'll need to re-install postgres or ruby. With rbenv I solved this just by switching to a different version: 1.9.3-p194 instead of 1.9.2-p290.


This is how I made it to work on Mavericks. Note: I already had installed postgresql 9.3 from homebrew.

  1. Update Xcode to 5.0 from App Store

  2. Install command line developer tools

    xcode-select --install

  3. Agree to Xcode license

    sudo xcodebuild -license

  4. Install gem

    ARCHFLAGS="-arch x86_64" gem install pg


So basically I did this ;-)

brew install postgres

I'm probably a bit late to the party here, but in my case I was using rbenv and upgrading to Ruby 2.2.3. I had to install Bundler to get mine to work, I had an old system version.

gem install bundler


As mentioned above this has to do with the fact of having two ruby archs on rbenv /usr/bin/ruby: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [i386:Mach-O executable i386] what i had to do was simply install pg gem forcing x86_64 arch to be used with this command:

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

Remember to have your bash_profile up to date

Add the path of your postgres, in this case im using Postgres app (OSX) instead of brew (https://postgresapp.com/) by default this is the location:

export PATH=/Applications/Postgres.app/Contents/Versions/10/bin:$PATH

Reload bash with

sudo vi ~/.bash_profile

After doing this i was able to finally successfully install pg gem

Hope this helps!


On Mac you can try this (works for me): gem install pg -- with-pg-include=/Library/PostgreSQL/9.5/include Fetching: pg-1.0.0.gem (100%) Building native extensions with: 'with-pg-include=/Library/PostgreSQL/9.5/include' This could take a while... Successfully installed pg-1.0.0 Parsing documentation for pg-1.0.0 Installing ri documentation for pg-1.0.0 Done installing documentation for pg after 3 seconds 1 gem installed

(this part "/Library/PostgreSQL/9.5/include" you must put your Postgres path)

참고URL : https://stackoverflow.com/questions/6209797/cant-find-the-postgresql-client-library-libpq

반응형