简体   繁体   English

尝试在Ruby on Rails中安装json时出现错误

[英]Getting Error when trying to install json in Ruby on Rails

Related Question: ERROR: Failed to build gem native extension 相关问题: 错误:无法构建gem本机扩展

I am trying to make ruby on rails (ruby 2.0.0p647 (2015-08-18) [x64-mingw32]) to work on my system. 我正在尝试在Rails上制作ruby(ruby 2.0.0p647(2015-08-18)[x64-mingw32])以在我的系统上工作。 I'm running Windows 8.1 (64 bit) 我正在运行Windows 8.1(64位)

The installation of ruby and rails goes smoothly but when i run rails new blog I get the following error: ruby和rails的安装过程很顺利,但是当我运行rails new blog ,出现以下错误:

       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. 我已经尝试安装ruby和开发套件3次(使用不同的ruby版本),但我一直收到相同的错误。

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. 我试图用不同的ruby版本(最新版本)重新安装ruby,并安装了x86版本的ruby和开发套件,但对我没有任何帮助。

This is not a direct answer because I've not had an issue with JSON before; 这不是直接的答案,因为我以前没有JSON的问题; 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. 每当您在系统上安装gem时,它都需要某些文件才能运行。

Most gems have all the files they need, but some need extra ones. 大多数gems具有所需的所有文件,但有些需要额外的文件。 mysql2 , rmagick and nokogiri are some of these. mysql2rmagicknokogiri就是其中一些。

The gems which need extra files have to load "dependencies" from your system to help them install properly. 需要额外文件的gems必须从系统中加载“依赖项”,以帮助它们正确安装。 They then compile the extra files with a c compiler . 然后,他们使用c compiler 编译额外的文件。 This is what building native extensions means. 这就是building native extensions含义。

When you install any gem, Ruby looks in ext/extconf.rb to see how to compile the extra files. 安装任何gem时,Ruby都会在ext/extconf.rb查找如何编译额外的文件。 This extconf.rb has compiler code which relies on the dependencies you add. extconf.rb具有依赖于您添加的依赖项的编译器代码。 This is why the error always says extconf.rb failed 这就是为什么错误总是说extconf.rb failed

-- -

You need a valid C compiler (DevKit includes gcc ) and a make program (I believe Devkit includes nmake ). 您需要一个有效的C compiler (DevKit包括gcc )和一个make程序(我相信Devkit包括nmake )。 Running extconf.rb with Ruby should use the gcc compiler in your PATH to create a Makefile . 使用Ruby运行extconf.rb应该在PATH中使用gcc编译器创建一个Makefile Running make on the Makefile will then build the gem's extra dependencies: 然后在Makefile上运行make将建立gem的额外依赖项:

在此处输入图片说明

-- -

The most common form of this error is for mysql2 : 此错误的最常见形式是mysql2

在此处输入图片说明

The fix is to include the dependencies on your system, link to it and then install the gem again. 解决方法是包括系统上的依赖项,链接到它,然后再次安装gem。 EG: 例如:

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

JSON JSON格式

It seems that JSON just has C headers which need to be compiled. 似乎JSON只是具有需要编译的C标头。

In this case, I would strongly recommend finding a new compiler & using it instead of Devkit. 在这种情况下,我强烈建议您找到一个新的编译器并使用它而不是Devkit。 It might not work, but I think your JSON needs to be compiled rather than have extra dependencies. 它可能不起作用,但是我认为您的JSON需要进行编译而不是具有额外的依赖关系。

We use MingW for compiling things in Windows. 我们使用MingW在Windows中编译内容。

Good ref: https://stackoverflow.com/a/33593870/1143732 良好的参考: https : //stackoverflow.com/a/33593870/1143732

You can download our MingW64 here , or download it yourself . 您可以在此处下载我们的MingW64 ,也可以自己下载

Install it & add it to your PATH. 安装并添加到您的PATH中。 It will take the place of Devkit; 它将取代Devkit; its more robust for compiling gems. 它对于编译gems更强大。

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

Type ruby extconf.rb and see what happens. 键入ruby extconf.rb ,看看会发生什么。 If it build a Makefile , type make and then make install 如果它Makefile一个Makefile ,请键入make ,然后make install

If not, post back what you found and we'll see if it gets fixed 如果没有,请发回您发现的内容,我们将看看它是否已解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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