ged / ruby-pg

A PostgreSQL client library for Ruby
Other
796 stars 181 forks source link

pg-0.10.0 fails to compile on OS X Snow Leopard #57

Closed ged closed 13 years ago

ged commented 13 years ago

Original report by Markus Wein (Bitbucket: nuclearsquid, ).


Using the following command to install pg:

gem install pg -- --ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby --with-pg-config=`which pg_config` --with-pgsql-lib=`pg_config --libdir` --with-pgsql-include=`pg_config --includedir`

I get the following output:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb --ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby --with-pg-config=/usr/local/pgsql/bin/pg_config --with-pgsql-lib=/usr/local/pgsql-9.0/lib --with-pgsql-include=/usr/local/pgsql-9.0/include
checking for /usr/local/pgsql/bin/pg_config... yes
Ruby cflags: "-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64 -fno-common -pipe"
MacOS X build: fixing architecture flags:
  finding flags common to both Ruby and PostgreSQL...
  testing for architecture: "i386"
  testing for architecture: "x86_64"
  common arch flags: -arch x86_64
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=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --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-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib

Gem files will remain installed in /Users/cypher/.rvm/gems/ruby-1.9.2-head/gems/pg-0.10.0 for inspection.
Results logged to /Users/cypher/.rvm/gems/ruby-1.9.2-head/gems/pg-0.10.0/ext/gem_make.out

If you'll take a look at the attached mkmf.log-gem, it complains about too few arguments to PQconnectdb, not that it doesn't exist.

I've installed PostgreSQL 9.0 using the package provided here: http://www.kyngchaos.com/software/postgres

I also tried building using the latest version from BitBucket (89348c8bb6d1) to try the new minimal extconf.rb, and got the following:

$ rake compile -- --with-pg-config=`which pg_config` --with-pgsql-lib=`pg_config --libdir` --with-pgsql-include=`pg_config --includedir`
(in /Users/cypher/Projects/ruby-pg)
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
cd tmp/x86_64-darwin10.4.0/pg_ext/1.9.2
/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby -I. ../../../../ext/extconf.rb --with-pg-config=/usr/local/pgsql/bin/pg_config --with-pgsql-lib=/usr/local/pgsql-9.0/lib --with-pgsql-include=/usr/local/pgsql-9.0/include
Using config values from /usr/local/pgsql/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)
*** ../../../../ext/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=../../../../ext
    --curdir
    --ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/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
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib
rake aborted!
Command failed with status (1): [/Users/cypher/.rvm/rubies/ruby-1.9.2-head/...]

(See full trace by running task with --trace)

mkmf.log-tip is attached.

ged commented 13 years ago

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Actually the problem with the gem install is a bit further towards the top:

ld: warning: in /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/libpq.dylib, 
    file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols:
  "_PQconnectdb", referenced from:
      _t in ccxwIhEo.o

If you install an extension for an x86_64 Ruby, you need to link against a library that's of the same architecture. You can check the architecture like so:

$ rvm 1.9.2 ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]

I installed the PostgreSQL package you linked to, but it put my libpq in /usr/local/pgsql-9.0/lib, not /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/libpq.dylib, so I'm not sure why pg_config thinks that's what it should be linking against. Is the pg_config returned by which pg_config /usr/local/pgsql-9.0/bin/pg_config? If not, I suspect you have another i386-only installation hanging around.

To be sure you're linking against the right stuff, try this:

  rvm 1.9.2-head gem install pg -- \
    --with-pg-config=/usr/local/pgsql-9.0/bin/pg_config

The tip install has the same architecture problem, and links against the same library under /Developer/SDKs.

ged commented 13 years ago

Original comment by Markus Wein (Bitbucket: nuclearsquid, ).


Yeah, /usr/local/pgsql is actually a symlink to pgsql-9.0:

$ which pg_config
/usr/local/pgsql/bin/pg_config
$ ls -l /usr/local/pgsql
lrwxr-xr-x  1 cypher  wheel     9B Dec  7 16:41 /usr/local/pgsql@ -> pgsql-9.0
$ pg_config
BINDIR = /usr/local/pgsql-9.0/bin
DOCDIR = /usr/local/pgsql-9.0/share/doc
INCLUDEDIR = /usr/local/pgsql-9.0/include
PKGINCLUDEDIR = /usr/local/pgsql-9.0/include
INCLUDEDIR-SERVER = /usr/local/pgsql-9.0/include/server
LIBDIR = /usr/local/pgsql-9.0/lib
PKGLIBDIR = /usr/local/pgsql-9.0/lib
LOCALEDIR = 
MANDIR = /usr/local/pgsql-9.0/man
SHAREDIR = /usr/local/pgsql-9.0/share
SYSCONFDIR = /usr/local/pgsql-9.0/etc
PGXS = /usr/local/pgsql-9.0/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-openssl' '--with-pam' '--with-krb5' '--with-gssapi' '--with-ldap' '--enable-thread-safety' '--with-bonjour' '--with-python' '--without-perl' '--enable-nls' '--with-libxml' 'CFLAGS=-Os -arch i386 -arch x86_64 -D_FILE_OFFSET_BITS=64' 'LD=gcc -arch i386 -arch x86_64 -nostdlib'
CC = gcc
CPPFLAGS = -I/usr/include/libxml2
CFLAGS = -Os -arch i386 -arch x86_64 -D_FILE_OFFSET_BITS=64 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv
CFLAGS_SL = 
LDFLAGS = -arch i386 -arch x86_64
LDFLAGS_SL = 
LIBS = -lintl -liconv -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lldap -lreadline -lz
VERSION = PostgreSQL 9.0.1

It turns out that /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib is actually a symlink to /usr/local/lib, where, for some reason, I had an older version of libpq installed. Moving it to a backup directory solved my problem, and I was able to install the pg gem just fine.

ged commented 13 years ago

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Ah good news. Thanks for following up!

ged commented 13 years ago

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Removing component: build-system (automated comment)