windows 下安装部分gem时出现 Could not create Makefile due to some reason 的解决办法

来源:互联网 发布:java技术总监年薪多少 编辑:程序博客网 时间:2024/06/07 05:28

现象描述:

如果你安装某个需要本地编译代码的gem 时出现了类似如下的错误,则符合本文章所谈论的情况:

C:/Develop/Ruby193/bin/ruby.exe extconf.rb checking for asprintf()... *** extconf.rb failed ***Could not create Makefile due to some reason, probably lack ofnecessary libraries and/or headers.  Check the mkmf.log file for moredetails.  You may need configuration options.Provided configuration options:--with-opt-dir--without-opt-dir--with-opt-include--without-opt-include=${opt-dir}/include--with-opt-lib--without-opt-lib=${opt-dir}/lib--with-make-prog--without-make-prog--srcdir=.--curdir--ruby=C:/Develop/Ruby193/bin/rubyC:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)You have to install development tools first.from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:894:in `block in have_func'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'from C:/Develop/Ruby193/lib/ruby/1.9.1/mkmf.rb:893:in `have_func'from extconf.rb:3:in `<main>'

mkmf.log中的内容是:

"gcc -o conftest -IC:/Develop/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Develop/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Develop/Ruby193/include/ruby-1.9.1 -I. -DFD_SETSIZE=2048  -DFD_SETSIZE=2048  -O3 -fno-omit-frame-pointer -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/Develop/Ruby193/lib -L.      -lmsvcrt-ruby191  -lshell32 -lws2_32 -limagehlp -lshlwapi  "In file included from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32:0,                 from conftest.c:1:C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:109:14: error: size of array 'ruby_check_sizeof_voidp' is negativeIn file included from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32:0,                 from conftest.c:1:C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h: In function 'rb_class_of':C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1333:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h: In function 'rb_type':C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1349:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]In file included from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1381:0,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32,                 from conftest.c:1:C:/Develop/Ruby193/include/ruby-1.9.1/ruby/missing.h: At top level:C:/Develop/Ruby193/include/ruby-1.9.1/ruby/missing.h:41:8: error: redefinition of 'struct timespec'In file included from c:\develop\devkit\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/process.h:12:0,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/win32.h:62,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/defines.h:223,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:67,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32,                 from conftest.c:1:c:\develop\devkit\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/sys/types.h:89:8: note: originally defined hereIn file included from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1381:0,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32,                 from conftest.c:1:C:/Develop/Ruby193/include/ruby-1.9.1/ruby/missing.h:48:8: error: redefinition of 'struct timezone'In file included from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/win32.h:63:0,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/defines.h:223,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby/ruby.h:67,                 from C:/Develop/Ruby193/include/ruby-1.9.1/ruby.h:32,                 from conftest.c:1:c:\develop\devkit\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/time.h:260:8: note: originally defined herechecked program was:/* begin */1: #include "ruby.h"2: 3: #include <winsock2.h>4: #include <windows.h>5: int main() {return 0;}/* end */


问题原因和解决办法:

可能你安装了和你使用的Ruby版本不对应的Devkit。

参考 http://rubyinstaller.org/downloads/ ,页面上有这样几行

WHICH DEVELOPMENT KIT?Down this page, several and different versions of Development Kits (DevKit) are listed. Please download the right one for your version of Ruby:Ruby 1.8.6 to 1.9.3: tdm-32-4.5.2Ruby 2.0.0: mingw64-32-4.7.2Ruby 2.0.0 x64 (64bits): mingw64-64-4.7.2
请下载和安装正确的DevKit


相关问题链接:

如果你在试图安装mysql有关的gem时出现类似问题,请阅读这篇帖子,看看是否能对你的问题有帮助。

http://www.ruby-forum.com/topic/1112530

另外,rubyinstaller也提供了很多有用的TroubleShooting

https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting#wiki-gems_fails_comspec_autorun

https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting#dll-conflicts-with-devkit-cause-native-gem-install-failures