错误:无法在 Mavericks 上构建 gem 原生扩展

Posted

技术标签:

【中文标题】错误:无法在 Mavericks 上构建 gem 原生扩展【英文标题】:ERROR: Failed to build gem native extension on Mavericks 【发布时间】:2013-11-03 08:14:26 【问题描述】:

我正在尝试在 OSX 10.9 上的 Rails 项目中运行 bundle。到达 pg gem 时失败并出现此错误:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile

make "DESTDIR="
compiling gvl_wrappers.c
clang: warning: argument unused during compilation: '-fno-fast-math'
compiling pg.c
clang: warning: argument unused during compilation: '-fno-fast-math'
pg.c:272:9: warning: implicit declaration of function 'PQlibVersion' is invalid in C99 [-Wimplicit-function-declaration]
        return INT2NUM(PQlibVersion());
               ^
In file included from pg.c:48:
In file included from ./pg.h:17:
In file included from /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby.h:33:
/Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:1167:21: note: instantiated from:
# define INT2NUM(v) INT2FIX((int)(v))
                    ^
pg.c:272:9: note: instantiated from:
        return INT2NUM(PQlibVersion());
               ^
pg.c:272:17: note: instantiated from:
        return INT2NUM(PQlibVersion());
                       ^
pg.c:375:48: error: use of undeclared identifier 'PQPING_OK'
        rb_define_const(rb_mPGconstants, "PQPING_OK", INT2FIX(PQPING_OK));
                                                      ^
pg.c:375:56: note: instantiated from:
        rb_define_const(rb_mPGconstants, "PQPING_OK", INT2FIX(PQPING_OK));
                                                              ^
pg.c:377:52: error: use of undeclared identifier 'PQPING_REJECT'
        rb_define_const(rb_mPGconstants, "PQPING_REJECT", INT2FIX(PQPING_REJECT));
                                                          ^
pg.c:377:60: note: instantiated from:
        rb_define_const(rb_mPGconstants, "PQPING_REJECT", INT2FIX(PQPING_REJECT));
                                                                  ^
pg.c:379:57: error: use of undeclared identifier 'PQPING_NO_RESPONSE'
        rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
                                                               ^
pg.c:379:65: note: instantiated from:
        rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
                                                                       ^
pg.c:381:56: error: use of undeclared identifier 'PQPING_NO_ATTEMPT'
        rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
                                                              ^
pg.c:381:64: note: instantiated from:
        rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
                                                                      ^
1 warning and 4 errors generated.
make: *** [pg.o] Error 1


Gem files will remain installed in /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247@skateboxes/gems/pg-0.17.0 for inspection.
Results logged to /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247@skateboxes/gems/pg-0.17.0/ext/gem_make.out

An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.0'` succeeds before bundling.

【问题讨论】:

【参考方案1】:

这适用于 Mavericks 和 Postgresapp:

gem install pg -v '0.17.0' -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

【讨论】:

对我也有用,对于那些复制此命令的人,请注意路径中的 Postgres.app 名称 Postgres/Contents/Versions/9.3/bin/pg_config 适用于任何使用 OS X Postgres 应用程序安装的人【参考方案2】:

当我尝试安装时

apt-get install libpq-dev

安装失败,未满足依赖问题,解决

apt-get remove libpq5

然后安装

apt-get install libpq-dev

终于解决了gem pg问题。

【讨论】:

【参考方案3】:

An error occurred while installing debugger (1.6.5), and Bundler cannot continue. Make sure that `gem install debugger -v '1.6.5'` succeeds before bundling.

我能够通过回滚到 Ruby v2.0.0 来修复这个错误。我运行的是 Ruby 2.1.1,这个调试器版本不支持它。如果您也遇到此问题,请务必检查您的 ruby​​ 版本。

【讨论】:

【参考方案4】:

你必须用你当前的版本配置 pg 我在 Yosemite 上使用了我的 9.4 版本。这是以下命令

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config 

你应该使用你自己的版本

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/(YOUR POSTGRES VERSION)/bin/pg_config 

然后做

bundle install

【讨论】:

【参考方案5】:

以下内容对我有用:

gem install pg -v '0.18.1' -- --with-pg config=/Library/PostgreSQL/9.3/bin/pg_config

【讨论】:

【参考方案6】:

这在 Mac OS X 10.9.3 和 Postgres.app 版本 9.3.4.2 上对我有用:

1) 安装 Postgres.app

2) bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

3)gem install pg -v '0.17.1'

4) bundle install

【讨论】:

对我有用的是gem install pg -v '0.18.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config【参考方案7】:

我刚刚让它运行了

ARCHFLAGS="-arch x86_64" gem install pg

使用 brew 安装 posgres 后

【讨论】:

【参考方案8】:

对我来说,当我这样做时它起作用了:

brew install postgresql

【讨论】:

谢谢,这解决了我的问题。 有时你需要在 brew install postgresql 之后 gem 卸载 pg 也为我工作!谢谢@user702342 为我工作!看起来使用 brew 解决了这个问题【参考方案9】:

对于使用 Mavericks、Rails 3.2.13、Ruby 2.0.0-p247、PostgreSQL 9.1 的我来说,我需要这样做:

gem install pg -v '0.15.1' -- --with-pg-config=/Library/PostgreSQL/9.1/bin/pg_config

【讨论】:

谢谢,这对我来说适用于 osx mavericks final 的 9.3.1 版本【参考方案10】:

还要确保您已升级 Xcode 以在 Mavericks 上重新安装命令行工具。 在终端类型中:

xcode-select --install

然后按照提示进行操作。

【讨论】:

这对我不起作用。我收到“无法安装该软件,因为它当前无法从软件更新服务器获得。”从 CLI 安装程序。进一步的研究表明 Xcode 5 默认带有 CLI 工具。 Sayanee 的回答对我有用。 @JosephJuhnke 我遇到了同样的问题。您可以从 Apple 网站手动下载和安装。这对我有用。developer.apple.com/downloads/… 奇怪的是,我记得我最近安装了这个软件,但是按照规定再次运行安装程序,解决了我的问题。谢谢! 我安装了 Xcode,但没有同意许可。运行 sudo xcodebuild -license 解决了这个问题。【参考方案11】:

尝试使用--with-pg-config 参数:

bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

显示pg_config的路径:

which pg_config

对于 Ubuntu 用户:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

然后:

bundle install

【讨论】:

以上是关于错误:无法在 Mavericks 上构建 gem 原生扩展的主要内容,如果未能解决你的问题,请参考以下文章

安装 pg gem;错误:无法构建 gem 原生扩展

无法使用 Postgres.app 在 Mavericks 中安装 pg gem

在 OSX 上安装 rmagick gem 时出错 - 错误:无法构建 gem 原生扩展

错误:安装 mysql2 时出错:错误:无法在 AWS Linux 上构建 gem 原生扩展

gem install rmagick -v 2.13.1 错误无法在 Mac OS 10.9.1 上构建 gem 本机扩展

Ruby Gem 安装 Json 在 Mavericks 和 Xcode 5.1 上失败 - 未知参数:'-multiply_definedsuppress'