Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

ruby - windows: rails: error installing bson_ext

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...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to this post <arpa/inet.h> 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 "<arpa/inet.h>"
  • 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 <winsock2.h>
#else
#include <arpa/inet.h>
#endif

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...