2014-09-29 69 views
5

嘗試安裝時bson_ext我看到錯誤......安裝JSON寶石正常工作也需要構建本地擴展 - 我已經嘗試了一切看到了類似的問題,沒有很好的答案窗口:軌道:錯誤安裝bson_ext

$ gem install bson_ext 
Temporarily enhancing PATH to include DevKit... 
Building native extensions. This could take a while... 
ERROR: Error installing bson_ext: 
     ERROR: Failed to build gem native extension. 

     c:/Ruby193/bin/ruby.exe extconf.rb 
checking for asprintf()... no 
checking for ruby/st.h... yes 
checking for ruby/regex.h... yes 
checking for ruby/encoding.h... yes 
creating Makefile 

make 
generating cbson-i386-mingw32.def 
compiling bson_buffer.c 
compiling cbson.c 
cbson.c:25:23: fatal error: arpa/inet.h: No such file or directory 
compilation terminated. 
make: *** [cbson.o] Error 1 


Gem files will remain installed in c:/Ruby193/lib/ruby/gems/1.9.1/gems/bson_ext- 
1.11.1 for inspection. 
Results logged to c:/Ruby193/lib/ruby/gems/1.9.1/gems/bson_ext-1.11.1/ext/cbson/ 
gem_make.out 

$ gem install json 
Temporarily enhancing PATH to include DevKit... 
Building native extensions. This could take a while... 
Successfully installed json-1.8.1 
1 gem installed 
Installing ri documentation for json-1.8.1... 
Installing RDoc documentation for json-1.8.1... 
+0

我遇到同樣的問題。其他人可以通過以下方式解決類似問題:'gem update --system;寶石安裝bson_ext「,但它不適合我。 – 2014-09-30 01:50:17

+0

我試圖手動安裝gem文件,從這裏下載文件:http://rubygems.org/gems/bson_ext。我得到了與上面相同的錯誤,提示要麼A)我們都有相同的環境問題或B)有一個問題與寶石文件。 – 2014-09-30 02:03:19

+0

我試過寶石更新 - 系統沒有爲我工作:( – lemon 2014-10-02 00:02:36

回答

9

根據this post<arpa/inet.h>不是Windows庫,所以應該使用winsock2.h來代替。

要改變這種引用,我已經做了以下**:

  • 轉到您的安裝文件夾(C:/Ruby193/lib/ruby/gems/1.9.1/gems/bson_ext-1.11 1.1)
  • 向下鑽取一個級別到cbson文件夾,找到cbson.c
  • 在你最喜歡的文本編輯器打開cbson.c,發現讀取#include "<arpa/inet.h>"
  • 把上面一行#include winsock2.h
  • 開行一個命令提示符下,瀏覽到安裝文件夾,然後運行gem build bson_ext.gemspec
  • 將新創建的.gem文件移到安全的地方(例如%userprofile%\ Desktop)。
  • 轉到gem文件夾並刪除整個bson_ext文件夾
  • 返回到命令提示符窗口,將目錄更改爲放置新創建的.gem文件的位置(cd%userprofile%\ Desktop,如果您完全按照這些步驟)
  • 運行gem install bson_ext-1.11.1.gem --local,現在應該安裝成功。

**巨大的警告:我只是通過一個mongodb的rails教程,我沒有任何功能代碼來測試它。雖然這消除了安裝錯誤,但我無法確定此修補程序是否完整。這個庫引用對於1.11.1版本是新的。如果安裝版本1.10.2,則不會發生此問題(gem install bson_ext -v 1.10.2)。我會讓你決定哪個解決方案對你更有意義。

編輯:基於a change to the bson-ruby project在GitHub上,一個更好的解決將是改變包括閱讀這樣的:上的devkit編譯時不需要

#ifdef _WIN32 
#include <winsock2.h> 
#else 
#include <arpa/inet.h> 
#endif 
+0

謝謝,它工作 – Jacky 2014-10-31 06:41:27

5

文件。

爲防止出現此錯誤,在預期位置創建一個空文件就足夠了。如果您的DevKit安裝在C:\ DevKit中,則該文件預計位於C:\ DevKit \ mingw \ include \ arpa \ inet.h

這也應該修復其他本機寶石。原因是,通常來自arpa/inet.h的定義已經來自大部分時間自動包含的其他包含文件。

0

我剛剛更新我的寶石到一個較舊的版本(從2.4.6到2.3),並工作。

0
Use this command 
gem update --system 2.3.0