ruby-on-rails - window : rails: error installing bson_ext

标签 ruby-on-rails ruby mongodb

当尝试安装 bson_ext 时,我看到错误...安装 json gem 工作正常,这还需要构建 native 扩展 - 我已经尝试了所有方法,但没有很好的答案

$ 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...

最佳答案

根据this post <arpa/inet.h>不是windows库,所以winsock2.h应改为使用。

要更改此引用,我已完成以下操作**:

  • 转到您的安装文件夹 (c:/Ruby193/lib/ruby/gems/1.9.1/gems/bson_ext-1.11.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现在应该可以成功安装 gem。

** 巨大的警告:我只是在运行 mongodb for rails 教程,我没有任何可运行的代码来测试它。虽然这消除了安装错误,但我无法确定此修复是否完整。此库引用是 1.11.1 版本的新引用。如果您安装版本 1.10.2,则不会出现此问题 (gem install bson_ext -v 1.10.2)。我将由您决定哪种解决方案对您更有意义。

编辑:基于a change to the bson-ruby project在 github 上,更好的解决方法是将包含更改为如下所示:

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

关于ruby-on-rails - window : rails: error installing bson_ext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26092541/

相关文章:

javascript - Mongoose /javascript : Can't update collection in Mongodb

java - java中的Mongo聚合: group with multiple fields

MongoDB在列表列表中查找值

ruby-on-rails - 如何在 Rails 3 中使用 Comet?

ruby-on-rails - 修改参数嵌套哈希的最佳方法是什么?

ruby - 如何使用CSV.open和CSV.foreach方法转换csv文件中的特定数据?

ruby-on-rails - 在 Rails 中,我可以在它返回之前在 Action 中访问 response.body 吗?

ruby-on-rails - 在 ruby​​ 对象上调用 .save 只为所有字符串传递 nil

ruby-on-rails - 如何在一定大小后删除rails日志文件

javascript - 使用rails_admin时向ckeditor添加插件