简而言之问题
我在 Windows 上运行时出现以下错误gem install json —platform=ruby
:
The system cannot find the path specified.
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
背景和一些调查
所以首先,我不是 Windows 用户,所以这对我来说是一个勇敢的新世界。从工作中继承了一台笔记本电脑,那里到处都是疯狂的库集合,我设法删除了所有以前安装的 ruby 和 Devkit,然后安装了以下内容:
- Ruby 1.9.3p484 与Ruby 安装程序进入
C:/Ruby193
- Ruby 2.0.0p353 与Ruby 安装程序进入
C:/Ruby200
- Devkit
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
(用于 ruby 1x)提取到C:/Ruby193-devkit
- Devkit
DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe
(Ruby 2x 的 32 位)提取到C:/Ruby200-devkit-x32
.
然后我将Pik 0.2.8安装为 gem,并按照安装说明运行pik_install
到一个新目录。C:/bin
我的 PATH 如下所示:
PATH=C:\bin;C:\Ruby193\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Support\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64
重要的事情就是这样,C:/bin
并且C:/Ruby193/bin
在路上。这意味着当我启动 shell 时默认加载 ruby 1.9.3,我可以使用pik use 2.0.0p353
. 换句话说, pik 工作正常。
Devkit旨在允许从 Windows 上的 gems 编译本机 C/C++ 二进制文件,以避免使用预编译的 windows 二进制文件。
因为我安装了两个版本的 ruby,每个版本都需要不同的 devkit(一个用于 2x,一个用于 1x),我必须为 devkit 设置两次:
cd C:/Ruby193-devkit
ruby dk.rb init
# Edit config.yml to remove all but Ruby193
ruby dk.rb install
cd C:/Ruby200-devkit
ruby dk.rb init
# Edit config.yml to remove all but C:/Ruby200
ruby dk.rb install
此时我应该已经能够gem install json —platform=ruby
成功运行了,但是得到了上面的错误。经过一番挖掘,我发现了这一点,它建议检查 COMSPEC 是否正确设置并从中删除任何 AutoRun 键HKEY_CURRENT_USER\Software\Microsoft\Command Processor
——我从 ANSIcon 中获得了一个并适当地删除了它。
不幸的是,我仍然无法安装 json gem。
然后让我感到震惊的是,可能使用了错误的 GCC 版本,或者没有找到。两个版本的 Devkit 带有不同版本的 gcc:
> C:\Ruby193-devkit\mingw\bin\gcc —version
gcc (tdm-1) 4.5.2
> C:\Ruby200-devkit-x32\mingw\bin\gcc —version
gcc (rubenv-4.7.2-release) 4.7.2
然后我想知道 pik 是否没有为我选择的特定版本的 ruby 加载 devtools 版本(以及因此 gcc),并且始终使用 1.9.3。感谢这篇文章,看来情况并非如此:
> pik use 193
> where ruby
C:\Ruby193\bin\ruby.exe
> cat C:\Ruby193\lib\ruby\site_ruby\devkit.rb
# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\Ruby193-devkit\\mingw\\bin') then
puts 'Temporarily enhancing PATH to include DevKit...'
ENV['PATH'] = 'C:\\Ruby193-devkit\\bin;C:\\Ruby193-devkit\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\Ruby193-devkit'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'
> pik use 200
> where ruby
C:\Ruby200\bin\ruby.exe
> cat C:\Ruby200\lib\ruby\site_ruby\devkit.rb
# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\Ruby200-devkit-x32\\mingw\\bin') then
phrase = 'Temporarily enhancing PATH to include DevKit...'
if defined?(Gem)
Gem.ui.say(phrase) if Gem.configuration.verbose
else
puts phrase
end
puts "Prepending ENV['PATH'] to include DevKit..." if $DEBUG
ENV['PATH'] = 'C:\\Ruby200-devkit-x32\\bin;C:\\Ruby200-devkit-x32\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\Ruby200-devkit-x32'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'
(我实际上在 Windows 上没有 cat 可用,但它可以提供更清晰的解释)
如您所见,devkit.rb 似乎正在将正确版本的 devkit 添加到路径中,这显然正在加载,因为我的错误包含“临时增强 PATH 以包含 DevKit...”。
回到原来的错误
它是:
The system cannot find the path specified.
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
不幸的是,结果日志并没有提供太多帮助。这就是 gem_make.out 的样子:
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
我认为这extconf.rb
可能会提供一些帮助,但我无法理解它:
require 'mkmf'
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
$CFLAGS << ' -O3'
end
if CONFIG['CC'] =~ /gcc/
$CFLAGS << ' -Wall'
unless $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
$CFLAGS << ' -O0 -ggdb'
end
end
$defs << "-DJSON_GENERATOR"
create_makefile 'json/ext/generator'
中的 MakefileC:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator
看起来像这样。对我来说,这个 Makefile 甚至正在被创建似乎很奇怪。
如果有更多 Windows/Ruby 经验的人能对此有所了解,那就太棒了!
PS。我使用的是 Windows 7 Professional SP1
更多挖掘后更新
因此,我想检查 devkit 是否使用正确的 devkit 目录明显地增强了路径。感谢另一个 SO question 的建议,我将 devkit 安装移到了 Ruby 目录中:
tdm devkit 现在存在,C:\Ruby193\devkit
而 mingw64 存在于C:\Ruby200\devkit
. 为每个 devkit运行后ruby dk.rb install -f
,我打开了两个 devkit.rb 文件以检查路径是否已正确更新。他们有,我更新了 puts,所以它应该打印“临时增强 PATH 确实包括 DevKit for 1.9”或“临时增强 PATH 确实包括 DevKit 2”。通过确认正在加载正确的 devkit:
C:\>pik 193
C:\>ruby -rdevkit -ve "puts ENV['PATH']"
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
Temporarily enhancing PATH to include DevKit for 1.9...
C:\Ruby193\devkit\bin;C:\Ruby193\devkit\mingw\bin;C:\bin;C:\Ruby193\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)
\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Pro
gram Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Su
pport\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin
;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\sy
swow64
C:\>pik 200
C:\>ruby -rdevkit -ve "puts ENV['PATH']"
ruby 2.0.0p353 (2013-11-22) [i386-mingw32]
Temporarily enhancing PATH to include DevKit for 2...
C:\Ruby200\devkit\bin;C:\Ruby200\devkit\mingw\bin;C:\bin;C:\Ruby200\bin;C:\windows;C:\windows\system32;C:\windows\system32\Wbem;c:\Program Files (x86)
\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Pro
gram Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files (x86)\Common Files\Apple\Mobile Device Su
pport\;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin
;C:/inpath;C:\Program Files (x86)\WinMerge;C:\ChromeDriver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\sy
swow64
这样看起来一切正常。但:
C:\>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit for 2...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby200/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
C:\>pik 193
C:\>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
这清楚地告诉我们两件事:
- 当我使用 ruby 1.9 时,正在加载其他一些 devkit.rb 文件,因为没有打印“for 1.9”消息。
- 这不太可能是实际问题,因为在任何一种情况下错误都是相同的。
我将看看是否可以使用生成的 Makefile 手动构建。