gem install json安装失败,出现struct timezone/timespec重定义的错误

8

我使用的是Windows系统,Ruby版本为1.9.3,安装了DevKit(在Win7 64位系统上全部是32位)。现在我尝试安装Rails,但是遇到了来自bundle的错误。如果我尝试运行(这是bundle抱怨的内容)

 gem install json

我遇到了以下错误信息:

D:\RubyTest>gem install json
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.

        D:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile

make
generating generator-i386-mingw32.def
compiling generator.c
In file included from d:/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1381:0,
                 from d:/Ruby193/include/ruby-1.9.1/ruby.h:32,
                 from ../fbuffer/fbuffer.h:5,
                 from generator.c:1:
d:/Ruby193/include/ruby-1.9.1/ruby/missing.h:41:8: error: redefinition of 'struc
t timespec'
In file included from d:\ruby193\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/../
../../../i686-w64-mingw32/include/process.h:12:0,
                 from d:/Ruby193/include/ruby-1.9.1/ruby/win32.h:62,
                 from d:/Ruby193/include/ruby-1.9.1/ruby/defines.h:223,
                 from d:/Ruby193/include/ruby-1.9.1/ruby/ruby.h:67,
                 from d:/Ruby193/include/ruby-1.9.1/ruby.h:32,
                 from ../fbuffer/fbuffer.h:5,
                 from generator.c:1:
d:\ruby193\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-ming
w32/include/sys/types.h:89:8: note: originally defined here
In file included from d:/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1381:0,
                 from d:/Ruby193/include/ruby-1.9.1/ruby.h:32,
                 from ../fbuffer/fbuffer.h:5,
                 from generator.c:1:
d:/Ruby193/include/ruby-1.9.1/ruby/missing.h:48:8: error: redefinition of 'struc
t timezone'
In file included from d:/Ruby193/include/ruby-1.9.1/ruby/win32.h:63:0,
                 from d:/Ruby193/include/ruby-1.9.1/ruby/defines.h:223,
                 from d:/Ruby193/include/ruby-1.9.1/ruby/ruby.h:67,
                 from d:/Ruby193/include/ruby-1.9.1/ruby.h:32,
                 from ../fbuffer/fbuffer.h:5,
                 from generator.c:1:
d:\ruby193\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-ming
w32/include/time.h:260:8: note: originally defined here
make: *** [generator.o] Error 1


Gem files will remain installed in D:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.7.
7 for inspection.
Results logged to D:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.7.7/ext/json/ext/ge
nerator/gem_make.out

有什么想法吗?
2个回答

22
Ruby 1.9.3是使用GCC 4.5.2编译的,该编译器是DevKitDevKit-tdm-32-4.5.2-20111229-1559-sfx.exe,可从RubyInstaller's download page下载。

您下载了新版本的DevKits,但这些版本与Ruby 2.0.0兼容,如RubyInstaller公告所示。

澄清一下:

  • Ruby 1.8.7:tdm-32-4.5.2
  • Ruby 1.9.2:tdm-32-4.5.2
  • Ruby 1.9.3:tdm-32-4.5.2
  • Ruby 2.0.0:mingw64-32-4.7.2(64位Ruby的64位版本)

我已经在RubyInstaller下载页面上添加了澄清说明。

希望这能帮到您。


1
这正是解决方案。我认为这值得放在RubyInstaller的下载页面上! :) 谢谢! - Henno
2
我已将此添加到下载页面的右侧列,置于所有内容的顶部 :-D - Luis Lavena
我认为最好的位置应该在下载列表上。类似于RUBY 2+:<mingw downloads>,RUBY <= 1.9.3:<tdm download>。 - FrontierPsycho
@FrontierPsycho,这已经反映在下载页面的应下载哪个版本的DevKit下了。 - Luis Lavena
我知道,但是很容易错误地选择“最新的”而根本没有阅读正确的列。这样,人们将始终选择正确的那个。我已在解释的位置发表了评论。 - FrontierPsycho
显示剩余2条评论

0
你可以打开在你的 Ruby 版本中找到的 "include" 目录下的 "win32.h" 文件。
然后注释掉声明 "clock_gettime" 和 "clock_getres" 函数的行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接