windows: rails: error installing bson_ext

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

when trying to install bson_ext i see the error...installing json gem works fine which also requires building native extensions - i have tried everything see similar questions with no good answer

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

回答1:

According to this post is not a windows library, so winsock2.h should be used instead.

To change this reference, I've done the following**:

  • Go to your installation folder (c:/Ruby193/lib/ruby/gems/1.9.1/gems/bson_ext-1.11.1)
  • Drill down a level into the cbson folder and find cbson.c
  • Open cbson.c in your favorite text editor and find the line that reads #include ""
  • Change that line to #include winsock2.h
  • Open a command prompt, browse to the installation folder, and run gem build bson_ext.gemspec
  • Move the newly-created .gem file someplace safe (%userprofile%\Desktop, for example).
  • Go up to the gem folder and delete the entire bson_ext folder
  • Back in your command prompt window, change directory to wherever you placed the newly-created .gem file (cd %userprofile%\Desktop, if you're following these steps exactly)
  • Run gem install bson_ext-1.11.1.gem --local and the gem should now install successfully.

** Huge caveat: I am just running through a mongodb for rails tutorial and I don't have any functioning code with which to test this. While this removes the installation error, I have no way of determining if this fix is a complete one. This library reference is new for the 1.11.1 release. If you install version 1.10.2 this issue will not occur (gem install bson_ext -v 1.10.2). I'll leave it to you to decide which solution makes more sense for you.

Edit: Based on a change to the bson-ruby project on github, a better fix would be to change that include to read like this:

#ifdef _WIN32 #include  #else #include  #endif 


回答2:

The file is not needed when compiling on DevKit.

To prevent this error it is enough to create an empty file at the expected location. If your DevKit was installed in C:\DevKit, the file would be expected at C:\DevKit\mingw\include\arpa\inet.h

This should also fix other native gems. The reasons is, that definitions usually coming from arpa/inet.h are already coming from other include files that are automatically included most of the time.



回答3:

Use this command gem update --system 2.3.0 


回答4:

I just updated my gem to an older version (from 2.4.6 to 2.3) and that worked.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!