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

现象描述:

如果你安装某个需要本地编译代码的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 of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  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/ruby
C:/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 negative
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: 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 here
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: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 here
checked 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.2
Ruby 2.0.0: mingw64-32-4.7.2
Ruby 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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:又报了另一个error $ make LD cdec /opt/compiler_tool/arm/armv7l-tizen-linux-gnueabi/bin/../lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/../../../../armv7l-tizen-linux-gnueabi/bin/ld: cannot find /lib/ld-linux.so.3: No such file or directory collect2: error: ld returned 1 exit status makefile:48: recipe for target 'cdec' failed make: *** \[cdec\] Error 1 /opt/compiler_tool/arm/armv7l-tizen-linux-gnueabi/lib$ ls gcc libarmv7l-tizen-linux-gnueabi-sim.a 。 引用\[2\]:the code model could not parse an included file,which might lead to incorrect code completion and highlighting,for example 。 引用\[3\]:4.make clean 后,执行make , 没想到gcc 命令 又不见了。。。 $ make PATH is /usr/bin:ATH CC cplay.c make: arm-none-linux-gnueabihf-gcc: Command not found makefile:57: recipe for target 'cplay.o' failed make: *** \[cplay.o\] Error 127 。 问题:could not parse makefile 回答: "could not parse makefile"是一个错误信息,它表示在解析makefile出现了问题。这可能是由于多种原因引起的。其中一种可能是makefile中的语法错误,导致解析器无法正确解析。另一种可能是makefile中引用的文件无法找到,比如在引用的文件路径中找不到所需的库文件。此外,还可能是由于环境变量配置不正确导致的,比如gcc命令无法找到。要解决这个问题,可以检查makefile中的语法错误,确保引用的文件路径正确,并检查环境变量配置是否正确。如果问题仍然存在,可能需要进一步调查和排除其他可能的原因。 #### 引用[.reference_title] - *1* *3* [记录一次makefile 异常问题解决方法](https://blog.csdn.net/dreamDay2016_11_11/article/details/131010400)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Qt creater警告:the code model could not parse an included file](https://blog.csdn.net/u012686154/article/details/85243010)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值