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

Kyl*_*cot 46 ruby ruby-on-rails pg ruby-on-rails-4 osx-mavericks

我试图bundle在OSX 10.9上运行我的Rails项目.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.
Run Code Online (Sandbox Code Playgroud)

小智 54

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

xcode-select --install
Run Code Online (Sandbox Code Playgroud)

然后按照提示操作.

  • 这对我不起作用.我得到"无法安装该软件,因为它目前无法从软件更新服务器获得." 从CLI安装程序.进一步的研究表明,Xcode 5默认使用CLI工具.Sayanee的回答对我有用. (19认同)
  • @JosephJuhnke我有同样的问题.您可以从Apple网站手动下载和安装.这对我有用.https://developer.apple.com/downloads/index.action?= command%20line%20tools# (2认同)

小智 47

对我来说,当我做的时候它起作用:

brew install postgresql
Run Code Online (Sandbox Code Playgroud)


Say*_*nee 27

这适用于我与小牛队和Postgresapp:

gem install pg -v '0.17.0' -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

  • 也为我工作,对于那些复制此命令的人,请注意路径中的Postgres.app名称 (3认同)
  • 对于使用OS X Postgres应用程序安装的任何人,Postgres/Contents/Versions/9.3/bin/pg_config (2认同)

MrY*_*iji 14

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

bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

要显示以下路径pg_config:

which pg_config
Run Code Online (Sandbox Code Playgroud)

对于Ubuntu用户:

sudo apt-get install postgresql
sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

然后:

bundle install
Run Code Online (Sandbox Code Playgroud)


Nei*_*ham 12

对于我使用Mavericks,Rails 3.2.13,Ruby 2.0.0-p247,PostgreSQL 9.1,我需要todo:

gem install pg -v '0.15.1' -- --with-pg-config=/Library/PostgreSQL/9.1/bin/pg_config
Run Code Online (Sandbox Code Playgroud)