rubyでmongoをインストールしようとしたらエラー

mongoをインストールしようとしたら

gem install mongo

 エラーが出た

ERROR: Error installing mongo:
ERROR: Failed to build gem native extension.

C:/Ruby200/bin/ruby.exe extconf.rb
creating Makefile

make "DESTDIR="
generating native-i386-mingw32.def
compiling native.c
In file included from c:/Ruby200/include/ruby-2.0.0/ruby/defines.h:153:0,
from c:/Ruby200/include/ruby-2.0.0/ruby/ruby.h:70,
from c:/Ruby200/include/ruby-2.0.0/ruby.h:33,
from native.c:26:
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h: In function 'rb_w32_pow':
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:801:5: warning: implicit declaration of function '_controlfp
' [-Wimplicit-function-declaration]
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:802:16: error: '_PC_64' undeclared (first use in this functi
on)
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:802:16: note: each undeclared identifier is reported only on
ce for each function it appears in
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:802:24: error: '_MCW_PC' undeclared (first use in this funct
ion)
native.c: In function 'rb_object_id_generator_next':
native.c:245:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
make: *** [native.o] Error 1


Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/bson-3.0.3 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/bson-3.0.3/ext/bson/gem_make.out

 エラーメッセージではwin32.hに_PC_64と_MCW_PCが定義されてないと言われているので、手動でそれらを追加する。

win32.h

...

static inline double
rb_w32_pow(double x, double y)
{
return powl(x, y);
}
#elif defined(__MINGW64_VERSION_MAJOR)

#ifndef _PC_64
#define _PC_64 0x00000000
#endif

#ifndef _MCW_PC
#define _MCW_PC 0x00030000
#endif
/*
* Set floating point precision for pow() of mingw-w64 x86.
* With default precision the result is not proper on WinXP.
*/
static inline double
rb_w32_pow(double x, double y)

...

 これでインストールできた。

 

参考

github.com