2013-12-16 34 views
0

我是新來的鐵軌,並嘗試從SQLite3切換到Postgres我的默認數據庫。我遇到了一個錯誤。我正在使用gem install pg並獲取此錯誤錯誤:安裝pg時出錯:錯誤:無法構建gem本機擴展。我使用的小牛OSX和Ruby 1.9.3,Rails的3.2.12和PG 9.3 -The的目標是部署一個示例應用程序來的Heroku(這似乎不支持的SQLite未能生成本機擴展

步驟我都試過。

鏈路1:Installing PG gem on OS X - failure to build native extension

鏈路2(Heroku的指令):https://devcenter.heroku.com/articles/sqlite3

編輯以舉出以下具體的錯誤消息:

HEAD https://rubygems.org/latest_specs.4.8.gz 
302 Moved Temporarily 
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz 
304 Not Modified 
HEAD https://rubygems.org/specs.4.8.gz 
302 Moved Temporarily 
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/specs.4.8.gz 
304 Not Modified 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/.gemtest 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/BSDL 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ChangeLog 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Contributors.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/History.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/LICENSE 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Manifest.txt 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/POSTGRES 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README-OS_X.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README-Windows.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README.ja.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README.rdoc 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Rakefile 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Rakefile.cross 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.def 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.txt 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/extconf.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/gvl_wrappers.c 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/gvl_wrappers.h 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg.c 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg.h 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_connection.c 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_errors.c 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_result.c 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg.sln 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg_18/pg.vcproj 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg_19/pg_19.vcproj 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/connection.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/constants.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/exceptions.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/result.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/array_insert.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_api.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_copyto.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_mixed.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/check_conn.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/copyfrom.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/copyto.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/cursor.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/disk_usage_report.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/issue-119.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/losample.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/minimal-testcase.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/notify_wait.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/pg_statistics.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/replication_monitor.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/test_binary_values.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/wal_shipper.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/warehouse_partitions.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/data/expected_trace.out 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/data/random_binary_data 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/lib/helpers.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg/connection_spec.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg/result_spec.rb 
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg_spec.rb 
Building native extensions. This could take a while... 
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb 
checking for pg_config... yes 
Using config values from /usr/local/bin/pg_config 
*** extconf.rb failed *** 
Could not create Makefile due to some reason, probably lack of 
necessary libraries and/or headers. Check the mkmf.log file for more 
details. You may need configuration options. 

Provided configuration options: 
    --with-opt-dir 
    --without-opt-dir 
    --with-opt-include 
    --without-opt-include=${opt-dir}/include 
    --with-opt-lib 
    --without-opt-lib=${opt-dir}/lib 
    --with-make-prog 
    --without-make-prog 
    --srcdir=. 
    --curdir 
    --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby 
    --with-pg 
    --without-pg 
    --with-pg-config 
    --without-pg-config 
    --with-pg_config 
    --without-pg_config 
    --with-pg-dir 
    --without-pg-dir 
    --with-pg-include 
    --without-pg-include=${pg-dir}/include 
    --with-pg-lib 
    --without-pg-lib=${pg-dir}/lib 
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError) 
You have to install development tools first. 
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0' 
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:476:in `try_link' 
    from extconf.rb:39:in `<main>' 
ERROR: Error installing pg: 
    ERROR: Failed to build gem native extension. 

    Building has failed. See above output for more information on the failure. 

Gem files will remain installed in /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/gems/pg-0.17.0 for inspection. 
Results logged to /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/gems/pg-0.17.0/ext/gem_make.out 
+0

你究竟在做什麼?你看到什麼錯誤?你使用的是什麼平臺(操作系統,Ruby版本)? – jonahb

+1

我正在使用gem install pg並獲取此錯誤錯誤:安裝pg時出錯:錯誤:無法構建gem本機擴展。我使用Mavericks OSX和Ruby 1.9.3,Rails 3.2.12和PG 9.3 – jfalkson

+0

您是否已經從Apple安裝了XCode,以便您擁有本機編譯器? – Gene

回答

1

它試圖構建gem pg,其中包含C或C++代碼,編譯階段不工作。在OS X下,您必須安裝XCode或通過其他方式獲取編譯器,並且您用於運行bundle install的shell必須在其路徑中包含編譯器。我在OS X下多次編譯pg,雖然我還沒有升級到小牛。

如果您安裝了XCode,則上述段落不適用。如果您嘗試gem install pg,您會收到有關錯誤的更多信息。嘗試一下併發布結果。

關鍵是「您必須先安裝開發工具。」這是一個強烈的暗示,你沒有一個合適的編譯器。 This page表示XCode必須是v5.01或更高版本。

+0

我安裝了XCode,並且安裝了pg,但是,即使我有XCode,gem install pg也不起作用 – jfalkson

+0

您是否檢查過版本?對於小牛隊必須是5.01。另一種可能性是XCode bin的路徑在你使用的shell中丟失了。從shell中嘗試'gcc --version'。 – Gene

+0

配置:--prefix =/Library/Developer/CommandLineTools/usr --with-gxx-include-dir =/usr/include/C++/4.2.1 Apple LLVM 5.0版(clang-500.2.79)(基於在LLVM 3.3svn上) 目標:x86_64-apple-darwin13.0.0 線程模型:posix – jfalkson

1

謝謝大家的幫忙。具體問題是由我在終端

brew install apple-gcc42 

爲了澄清運行下面的命令解決,我最近的XCode(命令行)和小牛,紅寶石1.9.3,Rails的3.2.12和PG 9.3 。我不確定爲什麼特定的命令在我已經安裝了命令行工具的情況下工作。的

gcc--version 

輸出的一個變化是--prefix=/Library/Developer/CommandLineTools/usr

變化

--prefix=/Applications/Xcode.app/Contents/Developer/usr 

而且,這種變化在實踐中摸索,但我不知道爲什麼這個固定的東西。

+0

幾年前的某段時間,Apple從其Xcode發行版中刪除了'gcc',並將'gcc'替換爲他們自己的'LLVM'和'clang'編譯器。這可能會打破「pg」,但它還沒有趕上。 – Gene