为bson Gem构建原生扩展失败

时间:2014-06-22 13:13:42

标签: ruby-on-rails ruby windows

我正在尝试通过运行gem install bson -v '2.3.0(按照bundle install的指示)在Windows上的rails应用程序(bson版本2.3.0)中安装Bson Gem,但安装失败每次都有相同的错误报告:

Building native extensions.  This could take a while...
ERROR:  Error installing bson:
        ERROR: Failed to build gem native extension.

    D:/Tools/Ruby/currentVersion/bin/ruby.exe extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
generating native-i386-mingw32.def
compiling native.c
In file included from d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/defin
es.h:153:0,
                 from d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/ruby.
h:70,
                 from d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby.h:33,

                 from native.c:26:
d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h: In function 'rb_w3
2_pow':
d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h:801:5: warning: imp
licit declaration of function '_controlfp' [-Wimplicit-function-declaration]
     unsigned int default_control = _controlfp(0, 0);
     ^
d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h:802:16: error: '_PC
_64' undeclared (first use in this function)
     _controlfp(_PC_64, _MCW_PC);
                ^
d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h:802:16: note: each
undeclared identifier is reported only once for each function it appears in
d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h:802:24: error: '_MC
W_PC' undeclared (first use in this function)
     _controlfp(_PC_64, _MCW_PC);
                        ^
make: *** [native.o] Error 1

make failed, exit code 2

Gem files will remain installed in D:/Tools/Ruby/currentVersion/lib/ruby/gems/2.
0.0/gems/bson-2.3.0 for inspection.
Results logged to D:/Tools/Ruby/currentVersion/lib/ruby/gems/2.0.0/extensions/x8
6-mingw32/2.0.0/bson-2.3.0/gem_make.out

正在运行ruby --version输出ruby 2.0.0p481 (2014-05-08) [i386-mingw32]

1 个答案:

答案 0 :(得分:3)

这是一个错误:交叉编译ruby_2_0_0到Windows失败(rb_w32_pow)。 你可以看到它:

https://www.ruby-forum.com/topic/4411245

要解决此问题,您可以手动添加_PC_64和_MCW_PC的定义。这些值的原始定义位于文件_mingw_float.h(但我找不到)

所以,你可以修改

d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/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)
{
    double r;
    unsigned int default_control = _controlfp(0, 0);
    _controlfp(_PC_64, _MCW_PC);
    r = pow(x, y);
    /* Restore setting */
    _controlfp(default_control, _MCW_PC);
    return r;
}

您还可以看到链接: https://github.com/mongoid/mongoid/issues/3489#issuecomment-34218208

相关问题