安装json Ruby gem时出错

6

我正在运行gem install json -v '1.8.1',但是我遇到了这个错误..

gem install json -v '1.8.1'
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170412-72871-wada1h.rb extconf.rb
creating Makefile

current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/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/johnwilliamson/.rvm/rubies/ruby-2.4.1/include/ruby-2.4.0/ruby/intern.h:795:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK(   \
        ^
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));
          ^        ~~~~~~~~~~
generator.c:840:25: error: use of undeclared identifier 'rb_cFixnum'
    } else if (klass == rb_cFixnum) {
                        ^
generator.c:842:25: error: use of undeclared identifier 'rb_cBignum'
    } else if (klass == rb_cBignum) {
                        ^
1 warning and 3 errors generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1 for inspection.
Results logged to /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/extensions/x86_64-darwin-16/2.4.0/json-1.8.1/gem_make.out

当我运行 gem install json 时,它可以成功安装版本号高于2的软件包,但是我想要安装 https://github.com/peatio/peatio,它需要特定的版本。还有其他想法吗?

1
仅仅是猜测:由于Ruby已经内置了json,我认为游戏的作者并不希望只有使用非常旧的Ruby版本(例如1.7,也许是1.8)的人使用Gem,而且原生的C接口无法与更新的Ruby版本兼容。我可以问一下,既然你已经在Ruby标准库中拥有了json,为什么还想要使用这个Gem呢? - user1934428
我自己不想使用这个 gem,但它是我想要安装的另一个 gem 的依赖项,而且我也找不到在 gem 文件中删除它的方法 :| - velua
3个回答

1
找到并更新引入JSON gem的gem应该可以解决问题。然而,对我有用的另一种方法是更新正在安装的JSON版本。
bundle update json

这起作用是因为它将JSON更新到1.8.6版本,该版本与较新的Rubies兼容。

-1

这似乎是json 1.8.1 gem的常见问题。如果您明确声明了它,可以使用不同版本的json,但在某些情况下,json 1.8.1是一个级联依赖项。例如,您可能会看到类似以下内容的东西

In Gemfile:
  rails was resolved to 4.1.5, which depends on
    actionmailer was resolved to 4.1.5, which depends on
      actionpack was resolved to 4.1.5, which depends on
        actionview was resolved to 4.1.5, which depends on
          activesupport was resolved to 4.1.5, which depends on
            json

在这种情况下,您只需要将顶级 gem(在本例中为 rails)更改为不同的版本。4.2.6 可以使用。

-1
问题是由于您不在正确的目录中引起的。请先进入您的Rails目录文件夹,然后像这样运行此命令:
rails@rails:~/rails_project/btc$ gem install json -v '1.8.1'

然后它就正常工作了。


那不正确。这个错误发生在我的Rails项目目录中。这是一个依赖解析错误。在我的情况下,通过使用一个依赖于不同版本的json的较新版本的rails来解决了这个问题。 - Kallaste
@Kallaste - 我正在使用Rails 5.0.7,但我仍然遇到相同的错误(它寻找json 1.8,而我在安装json 1.8时遇到了这个错误)。有什么想法如何解决这个问题吗? - Biju
@Biju - 请看下面我的回答。Json 1.8似乎是问题所在。我建议尝试使用不使用json 1.8的不同版本的Rails。我自己使用了4.2.6,所以我知道它可以工作。在此期间,您可以使用旧版的Rails,提交错误报告,并在问题解决后升级到当前版本。 - Kallaste

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接