新手问题 关于 bundle install 时安装 json 失败的问题

easonyuen · 2016年09月27日 · 最后由 huacnlee 回复于 2016年09月28日 · 5502 次阅读
  • 环境是 Ubuntu 16.04 desktop + Rails 4.2.2
  • 一开始我以为是缺少了某个 lib 包(前天硬盘坏了,重新装过系统),然后 stackoverflow 搜了一下,问题依旧没有解决,所以来打扰下诸位聚聚

  • 首先贴上错误的终端信息

    Fetching gem metadata from https://rubygems.org/.......
    Fetching version metadata from https://rubygems.org/..
    Fetching dependency metadata from https://rubygems.org/.
    Using rake 10.1.0
    ·
    ·
    ·
    

Using bootstrap-sass 3.0.3.0

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /tmp/bundler20160927-13647-olua81json-1.8.1/gems/json-1.8.1/ext/json/ext/generator /usr/local/bin/ruby -r ./siteconf20160927-13647-pqk3gf.rb extconf.rb creating Makefile

current directory: /tmp/bundler20160927-13647-olua81json-1.8.1/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" clean

current directory: /tmp/bundler20160927-13647-olua81json-1.8.1/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’: ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion] VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:238: recipe for target 'generator.o' failed make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /tmp/bundler20160927-13647-olua81json-1.8.1/gems/json-1.8.1 for inspection. Results logged to /tmp/bundler20160927-13647-olua81json-1.8.1/extensions/x86_64-linux/2.3.0-static/json-1.8.1/gem_make.out

An error occurred while installing json (1.8.1), and Bundler cannot continue. Make sure that gem install json -v '1.8.1' succeeds before bundling.

- 然后是我的Gemfile
```Ruby
source 'http://ruby.taobao.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'json',

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

错误信息说的不是很清楚嘛,,,

../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given

这类问题多是 json 没有兼容当前 ruby 版本,更新下 json 版本就好了,比如用 1.8.3 而不是 1.8.1;或者降级 ruby 版本,,,

另外,为了避免这类问题,可以在 Gemfile 中把 ruby 版本一起锁定,具体可以参考:http://bundler.io/gemfile_ruby.html

老问题了,一搜一大把

The same issue on ubuntu-trusty-64 running ruby 2.2.3. the solution is to install libgmp3-dev.

sudo apt-get install libgmp3-dev

https://github.com/flori/json/issues/253

需要 登录 后方可回复, 如果你还没有账号请 注册新账号