Ruby `json` gem does not compile - ruby-on-rails

I am trying to get Rails working on a Windows system. I installed RubyInstaller and the Devkit, but I cannot seem to get the json gem to install. When I try gem install json I get:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
make
generating generator-i386-mingw32.def
compiling generator.c
generator.c:1:0: error: CPU you selected does not support x86-64 instruction set
generator.c:1:0: error: CPU you selected does not support x86-64 instruction set
make: *** [generator.o] Error 1
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.3 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
It could be my Ruby versions (I have both 2.2 and 1.9), but I do not know. What is going on?

After #Azolo posted his comment, I discovered that the DevKit version I was using did not match the Ruby version I was running. The problem came to be because I needed Ruby 1.9.3 on the path for the Heroku client to function, but was trying to use 2.2 DevKit (as I typically use Ruby 2.2 for development.

Related

Error installing rails failed to build gem native extension

So I'm trying to Install Rails with this guide:
http://guides.rubyonrails.org/getting_started.html
And I keep getting this error (below).
Any suggestion?
I'm working on the cmd (windows 8).
(c) 2013 Microsoft Corporation. All rights reserved.
I'm typing: ruby -v
And then I get: ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32]
I'm typing: sqlite3 --version
And then I get: 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e
86726f2171d
I'm typing: gem install rails
And then I get:
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/websocket-driver-0
.6.5/ext/websocket-driver
C:/Ruby24-x64/bin/ruby.exe -r ./siteconf20180318-5748-xd7wo5.rb extconf.rb
creating Makefile
current directory: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/websocket-driver-0.6.5
/ext/websocket-driver
make "DESTDIR=" clean
current directory: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/websocket-driver-0.6.5
/ext/websocket-driver
make "DESTDIR="
generating websocket_mask-x64-mingw32.def
make: *** No rule to make target `/C/Ruby24-x64/include/ruby-2.4.0/ruby.h', need
ed by `websocket_mask.o'. Stop.
make failed, exit code 2
Gem files will remain installed in C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/websoc
ket-driver-0.6.5 for inspection.
Results logged to C:/Ruby24-x64/lib/ruby/gems/2.4.0/extensions/x64-mingw32/2.4.0
/websocket-driver-0.6.5/gem_make.out
I just had exactly the same problem with websocket-driver native extension (Windows 10) with exact the same error message:
make: *** No rule to make target `/C/Ruby24-x64/include/ruby-2.4.0/ruby.h', need
ed by `websocket_mask.o'. Stop.
make failed, exit code 2
The solution in my case was to pay attention during "MSYS2-Devkit" installation to chose the option "3" (MSYS2 and MINGW development toolchain)
After that "bundle install" in my case installed and compiled all dependencies of a rails project
Try using rvm using Cygwin. It should help solve ruby version issues.
see https://rvm.io/rvm/install

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

Error in installing json gem for ruby in windows

While I am trying to create the new rails project, I face to error that is related to the lack of json gem.
When I try to install json gem, this error happens:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating generator-x64-mingw32.def
compiling generator.c
In file included from c:/Ruby22-x64/include/ruby-2.2.0/ruby/ruby.h:29:0,
from c:/Ruby22-x64/include/ruby-2.2.0/ruby.h:33,
from ../fbuffer/fbuffer.h:5,
from generator.c:1:
c:/Ruby22-x64/include/ruby-2.2.0/ruby/defines.h:26:19: fatal error: stdio.h: No such file or directory
compilation terminated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-1.8.3 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/json-1.8.3/gem_make.out
If you want to install Ruby 2 (or greater) on Windows 7 (64 bit), you need to install DevKit 64 bit as well. Your Devkit has to be compatible with your operating system.
So, make sure you installed the correct Ruby and the compatible Devkit on your system.
See this tutorial for more information.
There was a group of gems which are dependent together. So, I had to install step by step.
As I did it based on error messages and one by one, I forgot to make a note about the steps.

Error installing rails 4 in mac

I am trying to set up rails in my mac(Yosemite) machine. But when I do
gem install rails
I get the following error. Please help.
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/Users/Paa/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb
creating Makefile
make clean
make
compiling generator.c
make: /usr/local/opt/gcc46/bin/gcc-4.6: No such file or directory
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/Paa/.rvm/gems/ruby-1.9.3-p547/gems/json-1.8.2 for inspection.
Results logged to /Users/Paa/.rvm/gems/ruby-1.9.3-p547/extensions/x86_64-darwin-13/1.9.1/json-1.8.2/gem_make.out
What am I missing here.??
I think rvm might be trying to use gcc 4.6, which doesn't work properly with rvm. I believe you can:
Uninstall gcc 4.6 (brew rm gcc46)
Pull the latest rvm (rvm get stable)
Retry gem install rails

ERROR: Failed to build gem native extension when installing rails

I'm on windows and trying to install rails. but I get the following error message:
Z:\AlexL\My Documents\rails>gem install rails
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe -r ./siteconf20150211-3312-5ie7vd.rb extconf.rb
creating Makefile
make clean
Makefile:165: *** target pattern contains no `%'. Stop.
make
Makefile:165: *** target pattern contains no `%'. Stop.
make failed, exit code 2
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.
2 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/js
on-1.8.2/gem_make.out
Ruby version is:
ruby 1.9.3p484
I've got this devkit installed DevKit-tdm-32-4.5.2-20111229-1559-sfx
in this folder:
C:\Ruby193\DevKit\
Not sure what else is wrong?
Looks the same as the issue being discussed here.
Apparently, there is a problem with Ruby 1.9.3 and newer RubyGems versions on Windows machines. Their quick-fix solution was to downgrade to an earlier version of RubyGems.
gem update --system 1.8.29
Once you have done that, confirm that gems -v returns 1.8.29 and try your command again.
Otherwise, you can upgrade to Ruby 2.X, which should also resolve this problem.

Resources