我如何构建" gem install json"?

时间:2016-10-07 16:53:50

标签: ruby-on-rails json ruby rubygems gemfile

我正在使用Rails 4.2.7。我正在尝试构建这个教程 - https://github.com/webguyian/bookstore,但是得到一个奇怪的错误,“安装json(1.8.0)时出错,而Bundler无法继续。”所以我尝试了“gem install json -v& #39; 1.8.0'”

localhost:bookstore-master davea$ gem install json -v '1.8.0'
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
/Users/davea/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20161007-50119-1huurrz.rb extconf.rb
creating Makefile

current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                              ^
/Users/davea/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/intern.h:797:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ (    \
        ^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
          ^        ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0 for inspection.
Results logged to /Users/davea/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-14/2.3.0/json-1.8.0/gem_make.out

我不知道这意味着什么或如何纠正它。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您使用的json gem的版本与Ruby> = 2.2不兼容。请使用至少版本1.8.2的json gem和Ruby 2.3。

有关功能和兼容性更改的详细信息,请参阅Changelog

也就是说,大多数情况下,您甚至不需要外部gem就可以使用Ruby中的JSON数据。 Ruby标准库附带的JSON module功能齐全,并且已经与Rails兼容。