使用ruby 2.4安装json 1.8.3时出错

时间:2017-02-20 00:32:30

标签: ruby

[版本信息]

ruby​​ 2.4.0p0(2016-12-24修订版57164)[x86_64-linux] / gem 2.0.3 / Windows 10

我跑了bundle install,它告诉我要运行gem install json -v '1.8.3'

我做到了并且无法构建gem原生扩展错误。

Building native extensions.  This could take a while...

ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.
    /home/ec2-user/.rvm/rubies/ruby-2.4.0/bin/ruby extconf.rb
creating Makefile

make
compiling generator.c
generator.c: In function ‘generate_json’:
generator.c:861:25: error: ‘rb_cFixnum’ undeclared (first use in this function)
     } else if (klass == rb_cFixnum) {
                         ^
generator.c:861:25: note: each undeclared identifier is reported only once for each function it appears in
generator.c:863:25: error: ‘rb_cBignum’ undeclared (first use in this function)
     } else if (klass == rb_cBignum) {
                         ^
generator.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
make: *** [generator.o] Error 1

Gem files will remain installed in /home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3 for inspection.
Results logged to /home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out

我查了几个文件。 我安装了Devkit和json 1.8.5,但我的项目保留了“安装json 1.8.3”的消息 我怎样才能解决这个问题?

/home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3包含:

../
./
data/
diagrams/
ext/
java/
lib/
tests/
tools/
install.rb*
.gitignore
.travis.yml
CHANGES
COPYING
COPYING-json-jruby
GPL
Gemfile
README-json-jruby.markdown
README.rdoc
Rakefile

/home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out包含:

user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
/home/ec2-user/.rvm/rubies/ruby-2.4.0/bin/ruby extconf.rb
creating Makefile

make
compiling generator.c
generator.c: In function ‘generate_json’:
generator.c:861:25: error: ‘rb_cFixnum’ undeclared (first use in this function)
     } else if (klass == rb_cFixnum) {
                         ^
generator.c:861:25: note: each undeclared identifier is reported only once for each function it appears in
generator.c:863:25: error: ‘rb_cBignum’ undeclared (first use in this function)
     } else if (klass == rb_cBignum) {
                         ^
generator.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
make: *** [generator.o] Error 1

8 个答案:

答案 0 :(得分:16)

尝试删除Gemfile.lock并再次运行bundle命令。它应该使用不同版本的json(即1.8.6)而没有问题。

答案 1 :(得分:14)

我最近遇到了同样的问题,试着看看是否有更新版本的任何宝石你依赖于json 1.8.3。这是因为Ruby 2.4统一Fixnum and Bignum into Integer。如果您能够升级到json 1.8.5或更高,则应该有助于解决您的问题。

您也可以尝试更新您正在使用的gem并尝试放宽版本限制(我发现这可以用于很多项目,但不是全部),如下所示:

gem 'json', '>= 1.8'

答案 2 :(得分:1)

在Gemfile.lock中

json (~>1.8.3)

然后做

bundle update

答案 3 :(得分:0)

我强制安装json 1.8.5并更改了Gemfile.lock中的条目,现在似乎正在运行。

答案 4 :(得分:0)

我遇到了同样的问题。可行的解决方案是我们应该先从gem中删除json

"gem uninstall json"

然后 安装

"sudo bundle install"
  

别忘了添加sudo。没有sudo就无法安装。

答案 5 :(得分:0)

我执行了以下步骤:在gemfile中插入上述命令(gem' json','> = 1.8')并且在运行包安装中出现错误事件我是实现了捆绑更新和安装的依赖关系。

答案 6 :(得分:0)

需要在Gemfile.lock中以“ json”开头的行更改为以下行

from django.db import models from django.db.models import Case, Value as V, When class ResultQuerySet(models.QuerySet): def annotate_positive_place(self): return self.annotate( positive_place=Case(When(place=0, then=V(1)), default=V(0)) ) class Result(models.Model): place = models.IntegerField() objects = ResultQuerySet.as_manager() Result.objects.annotate_positive_place().order_by('positive_place')

答案 7 :(得分:0)

对我有用的东西。

   1.)  gem install json_pure
   2.)    rvm list
          ruby-2.1.5 [ x86_64 ]
       =* ruby-2.7.1 [ x86_64 ]
   3.) rvm use 2.1.5
   4.) bundle install