Skip to content

json v1.8.3 doesn't work with ruby greater than 2.4

Many things happen in the last 3 years.

If you are like me and don't use ruby often, if you follow the README.md instructions running bundle install can exit with the following error:

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

    current directory: /home/modri/.rvm/gems/ruby-2.4.6/gems/json-1.8.3/ext/json/ext/generator
/home/modri/.rvm/rubies/ruby-2.4.6/bin/ruby -I /home/modri/.rvm/rubies/ruby-2.4.6/lib/ruby/site_ruby/2.4.0 -r ./siteconf20200323-10150-1fnctd0.rb extconf.rb
creating Makefile

current directory: /home/modri/.rvm/gems/ruby-2.4.6/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /home/modri/.rvm/gems/ruby-2.4.6/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c: In function ‘generate_json’:
generator.c:861:25: error: ‘rb_cFixnum’ undeclared (first use in this function); did you mean ‘mFixnum’?
     } else if (klass == rb_cFixnum) {
                         ^~~~~~~~~~
                         mFixnum
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); did you mean ‘rb_cFixnum’?
     } else if (klass == rb_cBignum) {
                         ^~~~~~~~~~
                         rb_cFixnum
generator.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
Makefile:242: recipe for target 'generator.o' failed
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/modri/.rvm/gems/ruby-2.4.6/gems/json-1.8.3 for inspection.
Results logged to /home/modri/.rvm/gems/ruby-2.4.6/extensions/x86_64-linux/2.4.0/json-1.8.3/gem_make.out

An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  fastlane was resolved to 1.59.0, which depends on
    supply was resolved to 0.3.1, which depends on
      google-api-client was resolved to 0.8.6, which depends on
        activesupport was resolved to 4.2.5.1, which depends on

Searching the error message on the internet I found that json v1.8.3 is incompatible with ruby 2.4 or greater.

Using ruby 2.3 make bundle install work fine.

References:

Edited by Modri