为 bson Gem 构建原生扩展失败 [英] Building native extensions fails for bson Gem

查看:71
本文介绍了为 bson Gem 构建原生扩展失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过运行 gem install bson -v '2.3.0(按照以下说明)在 Windows 上的 rails 应用程序(bson 版本 2.3.0)中安装 Bson Gembundle install),但每次安装都失败并报同样的错误:

I'm trying to install the Bson Gem in a rails application (bson version 2.3.0) on Windows by running gem install bson -v '2.3.0 (as instructed to do so by bundle install), but the installation fails everytime with the same error report:

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]

推荐答案

这是一个错误:将 ruby​​_2_0_0 交叉编译到 Windows 失败 (rb_w32_pow).你可以看到它:

It is a bug: cross-compiling ruby_2_0_0 to Windows is failing (rb_w32_pow). You can see it:

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

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

To solve the question, you could just add the definition of _PC_64 and _MCW_PC manually. The original definition for these value lies in file _mingw_float.h ( but i can not find it)

所以,你可以修改

d:/Tools/Ruby/currentVersion/include/ruby-2.0.0/ruby/win32.h

(发生错误的文件)通过添加这些值的定义.对我来说,

(File which the error occurs) by adding definition of these values. For me,

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

这篇关于为 bson Gem 构建原生扩展失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆