ruby-on-rails - 为 PostgreSQL 安装 ruby​​ gem 时出错

标签 ruby-on-rails ruby postgresql rubygems installation

我正在尝试配置 Rails 服务器以使用 PostgreSQL,但在安装 postgres gem 时卡住了。我已经在机器上成功安装了 PostgreSQL(并且可以将其用于其他应用程序)但是在尝试为其安装 ruby​​ gem 时出现错误。

我这样做:sudo gem install postgres

并得到如下输出:

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

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for main() in -lpq... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQsetClientEncoding()... no
checking for pg_encoding_to_char()... no
checking for PQfreemem()... no
checking for PQserverVersion()... no
checking for PQescapeString()... 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 i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common   -c libpq-compat.c
libpq-compat.c: In function ‘PQescapeBytea’:
libpq-compat.c:104: warning: incompatible implicit declaration of built-in function ‘sprintf’
libpq-compat.c: In function ‘PQunescapeBytea’:
libpq-compat.c:158: warning: incompatible implicit declaration of built-in function ‘strlen’
libpq-compat.c: In function ‘PQescapeBytea’:
libpq-compat.c:104: warning: incompatible implicit declaration of built-in function ‘sprintf’
libpq-compat.c: In function ‘PQunescapeBytea’:
libpq-compat.c:158: warning: incompatible implicit declaration of built-in function ‘strlen’
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 i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common   -c postgres.c
postgres.c:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration
/Library/PostgreSQL/8.4/include/libpq-fe.h:289: 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:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration
/Library/PostgreSQL/8.4/include/libpq-fe.h:289: 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)
lipo: can't open input file: /var/tmp//ccpTMtE2.out (No such file or directory)
make: *** [postgres.o] Error 1


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

我使用的是 Mac OS 10.6.4 和 Postgres 8.4 版。

想知道这里会发生什么或如何解决它吗?

最佳答案

看起来您正在使用 Posgres 的 EnterpriseDB 发行版,因此您需要在 Snow Leopard 上执行此操作:

$ export ARCHFLAGS='-arch i386'
$ sudo gem install pg -- --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config

关于ruby-on-rails - 为 PostgreSQL 安装 ruby​​ gem 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3391802/

相关文章:

ruby-on-rails - 如何将此字符串转换为毫秒?

sql - Postgresql 修改表

ruby-on-rails - 如果重复超过2次,如何删除换行符?

ruby-on-rails - Resque worker 使用 PostgreSQL 服务器失败

ruby-on-rails - 安装 Nokogiri-xmlsec-me-harder Mac El Capitan 时出错

ruby - 检查文件是否包含特定单词

postgresql - 第一次也是最后一次夜工时间

ruby-on-rails - 采摘多个连接表

ruby-on-rails - "Or"语句在 Rails 查询中不起作用

ruby-on-rails - 使用Mysql在共享服务器中部署Rails应用程序时出错