Ruby ruby 2.0 上 bson_ext 总是报告 not loaded

alucardpj · 2013年03月01日 · 最后由 blueplanet 回复于 2013年05月16日 · 5266 次阅读

我用 rvm 升级 ruby 到 2.0,装了 mongo gem,然后安装 bson_ext,但是用的时候总是报告 not loaded。信息如下:

** Notice: The native BSON extension was not loaded. **

For optimal performance, use of the BSON extension is recommended.

To enable the extension make sure ENV['BSON_EXT_DISABLED'] is not set
and run the following command:

  gem install bson_ext

If you continue to receive this message after installing, make sure that
the bson_ext gem is in your load path.

原来在 1.9.3 上装了以后没做什么设置就能用了,没报错。有人碰到这个问题吗?

到目录下用 require './xxx.so' 看具体错误

试一下能不能直接 require 进来,不行的话应该是没装上。

require 'bson_ext/cbson'
require 'bson/bson_c'

#2 楼 @ashchan 试了一下确实不能 require 进来

/home/pengjian/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- bson_ext/cbson (LoadError)
        from /home/pengjian/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from checkdoccount.rb:2:in `<main>'

但是 gem list 里面有啊

bson (1.8.3.rc1, 1.8.2)
bson_ext (1.8.3.rc1, 1.8.2)

这该怎么解决?

如果你是用 Mongoid 的话,尝试升级 Mongoid 吧,3.0 以后就没用 bson_ext 了

#3 楼 @alucardpj 我也遇到这种情况,貌似是 bson_ext 在 2.0 编译生成文件错误造成的,只要进入 2.0 的 gems 下的 bson_ext 把原来的 bson_ext/bson_ext 二进制文件重新修改为 bson_ext/bson_ext/cbson.bundle 就不会出现那个提示了

#5 楼 @ono_li 多谢,我试了一下,跟着 1.9.3 中安装的 bson_ext 目录结构把 bson_ext/bson_ext 改成 bson_ext/bson_ext/cbson.so 就好了。

#4 楼 @huacnlee mongoid 和 mongo 我都装了,mongo 是写简单脚本时用的,相对简单一些。

唉 同样的问题

This issue was resolved in today's update of rubygems version 2.0.2 and I just confirmed that locally. However, you'll need to re-install the gem before the fix will take effect.

gem update --system
gem install bson_ext

刚好在试 rails 4 rc1 + mongoid 的时候遇到这个问题了。回去试试

尝试了一下,确实如 @huacnlee 所说,最新版的 mongoid 已经不需要 bson_ext 了。

但在 rails 4 rc1 中使用的话,最好还是直接使用 github 上的最新代码才能正常执行 rails g mongoid:config

gem "mongoid", git: 'https://github.com/mongoid/mongoid.git'
需要 登录 后方可回复, 如果你还没有账号请 注册新账号