Skip navigation

Tag Archives: ruby-gem

Spent almost 2hrs in figuring how to get this done successfully. The error messages are so cryptic.

First of all, make sure u have postgres installed on your machine and the path to the postgres bin folder is in the $PATH enviroment variable. You can follow http://anooj.me/blog/?p=64 to set PATH.

To confirm, type pg_config in terminal to see if its in PATH. It should display the pg related configuration


anooj.n@dv-mac-anooj-n ~$ pg_config
BINDIR = /Library/PostgreSQL/8.4/bin
DOCDIR = /Library/PostgreSQL/8.4/doc/postgresql
HTMLDIR = /Library/PostgreSQL/8.4/doc/postgresql
INCLUDEDIR = /Library/PostgreSQL/8.4/include
PKGINCLUDEDIR = /Library/PostgreSQL/8.4/include/postgresql
INCLUDEDIR-SERVER = /Library/PostgreSQL/8.4/include/postgresql/server
LIBDIR = /Library/PostgreSQL/8.4/lib
PKGLIBDIR = /Library/PostgreSQL/8.4/lib/postgresql
LOCALEDIR = /Library/PostgreSQL/8.4/share/locale
MANDIR = /Library/PostgreSQL/8.4/share/man
SHAREDIR = /Library/PostgreSQL/8.4/share/postgresql
SYSCONFDIR = /Library/PostgreSQL/8.4/etc/postgresql
PGXS = /Library/PostgreSQL/8.4/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/Users/buildfarm/pginstaller/server/staging/osx' '--with-openssl' '--with-perl' '--with-python' '--with-tcl' '--with-bonjour' '--with-pam' '--with-krb5' '--enable-thread-safety' '--with-libxml' '--with-ossp-uuid' '--with-includes=/usr/local/include/libxml2:/usr/local/include' '--docdir=/Users/buildfarm/pginstaller/server/staging/osx/doc/postgresql' '--with-libxslt' 'CFLAGS=-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -headerpad_max_install_names -arch ppc -arch i386' 'LDFLAGS=-L/usr/local/lib'
CC = gcc -no-cpp-precomp
CPPFLAGS = -I/usr/include/libxml2 -I/usr/local/include/libxml2 -I/usr/local/include
CFLAGS = -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -headerpad_max_install_names -arch ppc -arch i386 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv
CFLAGS_SL =
LDFLAGS = -L/usr/local/lib -L/usr/lib
LDFLAGS_SL =
LIBS = -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lz -lreadline -lm
VERSION = PostgreSQL 8.4.8

Initially went straight and fired:


anooj.n@dv-mac-anooj-n ~$ sudo gem install ruby-pg
Building native extensions. This could take a while...
ERROR: Error installing ruby-pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb –with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config
checking for main() in -lpq… yes
checking for libpq-fe.h… yes
checking for libpq/libpq-fs.h… yes
checking for PQconnectionUsedPassword()… no
checking for PQisthreadsafe()… no
checking for PQprepare()… no
checking for PQexecParams()… no
checking for PQescapeString()… no
checking for PQescapeStringConn()… no
checking for lo_create()… no
checking for pg_encoding_to_char()… no
checking for PQsetClientEncoding()… no
creating Makefile

make
gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DHAVE_LIBPQ_FE_H -DHAVE_LIBPQ_LIBPQ_FS_H -I/Library/PostgreSQL/8.4/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -c compat.c
In file included from compat.c:16:
compat.h:38:2: error: #error PostgreSQL client version too old, requires 7.3 or later.
In file included from compat.c:16:
compat.h:69: error: conflicting types for ‘PQconnectionNeedsPassword’
/Library/PostgreSQL/8.4/include/libpq-fe.h:293: error: previous declaration of ‘PQconnectionNeedsPassword’ was here
compat.h:70: error: conflicting types for ‘PQconnectionUsedPassword’
/Library/PostgreSQL/8.4/include/libpq-fe.h:294: error: previous declaration of ‘PQconnectionUsedPassword’ was here
compat.h:123: error: redeclaration of enumerator ‘PQERRORS_TERSE’
/Library/PostgreSQL/8.4/include/libpq-fe.h:105: error: previous definition of ‘PQERRORS_TERSE’ was here
compat.h:124: error: redeclaration of enumerator ‘PQERRORS_DEFAULT’
/Library/PostgreSQL/8.4/include/libpq-fe.h:106: error: previous definition of ‘PQERRORS_DEFAULT’ was here
compat.h:126: error: redeclaration of enumerator ‘PQERRORS_VERBOSE’
/Library/PostgreSQL/8.4/include/libpq-fe.h:108: error: previous definition of ‘PQERRORS_VERBOSE’ was here
compat.h:126: error: conflicting types for ‘PGVerbosity’
/Library/PostgreSQL/8.4/include/libpq-fe.h:108: error: previous declaration of ‘PGVerbosity’ was here
compat.h:130: error: redeclaration of enumerator ‘PQTRANS_IDLE’
/Library/PostgreSQL/8.4/include/libpq-fe.h:96: error: previous definition of ‘PQTRANS_IDLE’ was here
compat.h:131: error: redeclaration of enumerator ‘PQTRANS_ACTIVE’
/Library/PostgreSQL/8.4/include/libpq-fe.h:97: error: previous definition of ‘PQTRANS_ACTIVE’ was here
compat.h:132: error: redeclaration of enumerator ‘PQTRANS_INTRANS’
/Library/PostgreSQL/8.4/include/libpq-fe.h:98: error: previous definition of ‘PQTRANS_INTRANS’ was here
compat.h:133: error: redeclaration of enumerator ‘PQTRANS_INERROR’
/Library/PostgreSQL/8.4/include/libpq-fe.h:99: error: previous definition of ‘PQTRANS_INERROR’ was here
compat.h:135: error: redeclaration of enumerator ‘PQTRANS_UNKNOWN’
/Library/PostgreSQL/8.4/include/libpq-fe.h:101: error: previous definition of ‘PQTRANS_UNKNOWN’ was here
compat.h:135: error: conflicting types for ‘PGTransactionStatusType’
/Library/PostgreSQL/8.4/include/libpq-fe.h:101: error: previous declaration of ‘PGTransactionStatusType’ was here
compat.h:140: error: conflicting types for ‘PQtransactionStatus’
/Library/PostgreSQL/8.4/include/libpq-fe.h:285: error: previous declaration of ‘PQtransactionStatus’ was here
compat.h:141: error: conflicting types for ‘PQparameterStatus’
/Library/PostgreSQL/8.4/include/libpq-fe.h:287: error: previous declaration of ‘PQparameterStatus’ was here
compat.h:155: error: conflicting types for ‘PQsetErrorVerbosity’
/Library/PostgreSQL/8.4/include/libpq-fe.h:309: error: previous declaration of ‘PQsetErrorVerbosity’ was here
compat.h:165:2: error: #error unsupported postgresql version, requires 7.3 or later.
compat.c: In function ‘PQsetClientEncoding’:
compat.c:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:49: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:55: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:61: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:67: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:73: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:79: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:85: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:93: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:102: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:115: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:125: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:137: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:143: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:151: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:159: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:167: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:173: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:179: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:191: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:197: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:203: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:209: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:218: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:225: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:268: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:327: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:374: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:453: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
compat.c:527: error: old-style parameter declarations in prototyped function definition
compat.c:527: error: expected ‘{’ at end of input
make: *** [compat.o] Error 1

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/ruby-pg-0.7.9.2008.01.28 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/ruby-pg-0.7.9.2008.01.28/ext/gem_make.out

The error mentioned something like "PostgreSQL client version too old, requires 7.3 or later.". Don't get fooled by this.

Now try,


anooj.n@dv-mac-anooj-n ~$ sudo env ARCHFLAGS="-arch i386" gem install ruby-pg -- --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config
Password:
Building native extensions. This could take a while...
Successfully installed ruby-pg-0.7.9.2008.01.28
1 gem installed
Installing ri documentation for ruby-pg-0.7.9.2008.01.28...
Installing RDoc documentation for ruby-pg-0.7.9.2008.01.28...

PEACE. This worked for me.. :) Hopefully this should work for everyone.

UPDATE:
on running rake routes i started getting the following error:


anooj.n@dv-mac-anooj-n ~/workspace/pg/pgweb$ bundle exec rake routes
(in /Users/anooj.n/workspace/pg/pgweb)
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found. Did find:
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle

To fix this, i had install postgres manually, i.e. download and compile the source manually which is pretty trivial.

had to change to install command also to


anooj.n@dv-mac-anooj-n ~$ sudo env ARCHFLAGS="-arch x86_64" gem install ruby-pg -- --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config