Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...
like image 971
lemon Avatar asked Sep 29 '14 04:09

lemon


2 Answers

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
like image 111
Brick Avatar answered Oct 14 '22 08:10

Brick


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.

like image 35
mlehmk Avatar answered Oct 14 '22 08:10

mlehmk