2014-09-29 70 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