2014-10-20 141 views
1

我試圖在我的系統上安裝pg gem(macbook pro運行10.10,Postgresql 9.3.5_1,Ruby 1.9.3p547,Xcode v6.1(6A1052c)):在OSX 10.10上安裝pg gem時遇到的麻煩

ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config 

返回此:

Building native extensions with: '--with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config' 
This could take a while... 
ERROR: Error installing pg: 
    ERROR: Failed to build gem native extension. 

    /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config 
Using config values from /usr/local/Cellar/postgresql/9.3.5_1/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 
    --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=/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/bin/ruby 
    --with-pg 
    --without-pg 
    --with-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 
/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/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 /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0' 
    from /Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/mkmf.rb:476:in `try_link' 
    from extconf.rb:39:in `<main>' 

extconf failed, exit code 1 

Gem files will remain installed in /Users/thomas/.rvm/gems/ruby-1.9.3-p547/gems/pg-0.17.1 for inspection. 
Results logged to /Users/thomas/.rvm/gems/ruby-1.9.3-p547/extensions/x86_64-darwin-13/1.9.1/pg-0.17.1/gem_make.out 

什麼?

我敢肯定,我已經安裝了開發工具:

xcode-select --print-path 

返回:

/Applications/Xcode.app/Contents/Developer 

我mkmf.log文件包含此:

"/usr/local/opt/gcc46/bin/gcc-4.6 -o conftest -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1/x86_64-darwin13.4.0 -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1/ruby/backward -I/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/include/ruby-1.9.1 -I. -I/usr/local/Cellar/postgresql/9.3.5_1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/thomas/.rvm/rubies/ruby-1.9.3-p547/lib -L/usr/local/Cellar/postgresql/9.3.5_1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib  -lruby.1.9.1 -lpthread -ldl -lobjc " 
checked program was: 
/* begin */ 
1: #include "ruby.h" 
2: 
3: int main(int argc, char **argv) 
4: { 
5: return 0; 
6: } 
/* end */ 

隱而不宣人有關於這裏發生了什麼的線索?任何幫助將不勝感激!

+0

您的'xcode-select -print-path'命令顯示Xcode已安裝,但未必安裝最新的命令行工具,它們分別安裝在不同的軟件包中。 'xcode-select --install'可以用來安裝它們。如果失敗 - 「無法安裝軟件,因爲它目前不能從軟件更新服務器獲得」,那麼您必須從Apple開發人員網站手動下載它們。 – 2014-10-20 17:15:12

+0

@SomeDeveloper我已經完成了這個任務(分別安裝了10.10命令行工具),但我仍然得到上面的錯誤: -/ – thomax 2014-10-20 20:08:08

+0

您的mkmf.log文件顯示'/ usr/local/opt/gcc46/bin/gcc-4.6' ,它看起來像一個brew或ports安裝的編譯器。不應該是'/ usr/bin/gcc'嗎?可能只是一個路徑問題? – 2014-10-20 22:46:10

回答

6

這解決了我的問題

首先,你應該下載Postgres的應用程序(http://postgresapp.com/),並把它放在你的應用程序文件夾。提取並打開它,現在將其寫入控制檯。

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config 

我寫了9.4因爲這是我的最新版本。