Installing postgres gem on OSX (Leopard with MacPorts PostgreSQL82)
Unfortunately, out of the box, the postgres gem fails to install with the MacPorts postgres82-server install. There are two problems. The first is it can’t find pg_config. The second is incorrect architecture detection (thanks to Andreas Flierl at the RubyForge postgres module forums for pointing out the fix).
ERROR: Error installing postgres:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install postgres
extconf.rb:73: command not found: pg_config --bindir
The fix for this one is to fix the path temporarily:
export PATH=/opt/local/lib/postgresql82/bin/:$PATH
Then when we retry the gem installation, we’ll get the following error(s):
postgres.c:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration /opt/local/include/postgresql82/libpq-fe.h:262: error: previous declaration of ‘PQserverVersion’ was here postgres.c:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration /opt/local/include/postgresql82/libpq-fe.h:262: error: previous declaration of ‘PQserverVersion’ was here postgres.c: In function ‘Init_postgres’: postgres.c:2676: error: ‘pgconn_protocol_version’ undeclared (first use in this function) postgres.c:2676: error: (Each undeclared identifier is reported only once postgres.c:2676: error: for each function it appears in.) postgres.c:2677: error: ‘pgconn_server_version’ undeclared (first use in this function) postgres.c: In function ‘Init_postgres’: postgres.c:2676: error: ‘pgconn_protocol_version’ undeclared (first use in this function) postgres.c:2676: error: (Each undeclared identifier is reported only once postgres.c:2676: error: for each function it appears in.) postgres.c:2677: error: ‘pgconn_server_version’ undeclared (first use in this function) lipo: can't open input file: /var/tmp//ccBatpen.out (No such file or directory) make: *** [postgres.o] Error 1
These are fixed by specifying a specific architecture to use.
The following commands worked well for me:export PATH=/opt/local/lib/postgresql82/bin/:$PATH sudo env ARCHFLAGS="-arch i386" gem install --remote postgres
