简体   繁体   中英

Getting Error when trying to install json in Ruby on Rails

Related Question: ERROR: Failed to build gem native extension

I am trying to make ruby on rails (ruby 2.0.0p647 (2015-08-18) [x64-mingw32]) to work on my system. I'm running Windows 8.1 (64 bit)

The installation of ruby and rails goes smoothly but when i run rails new blog I get the following error:

       Installing json 1.8.3 with native extensions

        Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
        .
        C:/Ruby200-x64/bin/ruby.exe extconf.rb
    creating Makefile

    make "DESTDIR="
    generating generator-x64-mingw32.def
    compiling generator.c
    linking shared-object json/ext/generator.so
    c:/ruby200-x64/mingw64/mingw64/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../.
    ./../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s
    c:/ruby200-x64/mingw64/mingw64/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../.
    ./../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s
    collect2.exe: error: ld returned 1 exit status
    make: *** [generator.so] Error 1
Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/json-
1.8.3 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/json-1.8.3/ext/json/ex
t/generator/gem_make.out
Using minitest 5.8.3
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types 2.99
Using arel 6.0.3
Installing debug_inspector 0.0.2 with native extensions

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.

I have already tried installing ruby and the development kit 3 times (with different ruby versions) I keep getting the same error.

I have tried the solution in the question above.

I get a very similar error:

    C:\Ruby200-x64>gem install --local json-1.8.3.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing json-1.8.3.gem:
        ERROR: Failed to build gem native extension.

    C:/Ruby200-x64/bin/ruby.exe extconf.rb
creating Makefile

I have tried to reinstall ruby with different ruby version (the newest one) as well as installing both of the x86 versions of ruby and the development kit which did nothing for me.

This is not a direct answer because I've not had an issue with JSON before; I'll tell you about the error itself though - just so you know what's going on.


Whenever you install a gem on your system, it needs certain files to run.

Most gems have all the files they need, but some need extra ones. mysql2 , rmagick and nokogiri are some of these.

The gems which need extra files have to load "dependencies" from your system to help them install properly. They then compile the extra files with a c compiler . This is what building native extensions means.

When you install any gem, Ruby looks in ext/extconf.rb to see how to compile the extra files. This extconf.rb has compiler code which relies on the dependencies you add. This is why the error always says extconf.rb failed

--

You need a valid C compiler (DevKit includes gcc ) and a make program (I believe Devkit includes nmake ). Running extconf.rb with Ruby should use the gcc compiler in your PATH to create a Makefile . Running make on the Makefile will then build the gem's extra dependencies:

在此处输入图片说明

--

The most common form of this error is for mysql2 :

在此处输入图片说明

The fix is to include the dependencies on your system, link to it and then install the gem again. EG:

 gem install mysql2 --platform=ruby -- --with-mysql-dir="c:/path/to/mysql"

JSON

It seems that JSON just has C headers which need to be compiled.

In this case, I would strongly recommend finding a new compiler & using it instead of Devkit. It might not work, but I think your JSON needs to be compiled rather than have extra dependencies.

We use MingW for compiling things in Windows.

Good ref: https://stackoverflow.com/a/33593870/1143732

You can download our MingW64 here , or download it yourself .

Install it & add it to your PATH. It will take the place of Devkit; its more robust for compiling gems.

Once you've done it, go to your ruby\\lib\\ruby\\gems\\[version]\\json...\\ext

Type ruby extconf.rb and see what happens. If it build a Makefile , type make and then make install

If not, post back what you found and we'll see if it gets fixed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM