在 Windows 7 上“无法构建 gem 本机扩展"(系统找不到指定的路径) [英] 'Failed to build gem native extension' on Windows 7 (The system cannot find the path specified)

查看:53
本文介绍了在 Windows 7 上“无法构建 gem 本机扩展"(系统找不到指定的路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上运行 gem install json —platform=ruby 时出现以下错误:

I'm on Windows and am getting the following error when running 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,然后安装了以下内容:

Background and some Investigations

So first off, I'm not a Windows person so this is a brave new world for me. Having inherited a laptop from work that had a mad collection of libraries spread all over it I've managed to remove all previous installations of ruby and the Devkit and then installed the following:

  • Ruby 1.9.3p484 和 Ruby InstallerC:/Ruby193
  • Ruby 2.0.0p353 和 Ruby InstallerC:/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(32 位用于 ruby​​ 2x)提取到 C:/Ruby200-devkit-x32.
  • Ruby 1.9.3p484 with Ruby Installer into C:/Ruby193
  • Ruby 2.0.0p353 with Ruby Installer into C:/Ruby200
  • Devkit DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe (for ruby 1x) extracted into C:/Ruby193-devkit
  • Devkit DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe (32-bit for ruby 2x) extracted into C:/Ruby200-devkit-x32.

然后我将 Pik 0.2.8 作为 gem 安装并运行 pik_install按照安装说明进入一个新目录 C:/bin.

I then installed Pik 0.2.8 as a gem and ran pik_install into a new directory C:/bin as per the installation instructions.

我的路径如下所示:

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:/binC:/Ruby193/bin 在路径中.这意味着在我启动 shell 时默认加载 ruby​​ 1.9.3,我可以使用 pik use 2.0.0p353 成功切换到 2.0.0.换句话说,pik 工作正常.

The important things being that C:/bin and C:/Ruby193/bin are in the path. This means that ruby 1.9.3 is loaded by default when I fire up a shell and I can successfully switch to 2.0.0 with pik use 2.0.0p353. In other words, pik works fine.

Devkit 旨在允许编译来自Windows 上的 gems,以避免使用预编译的 Windows 二进制文件.

Devkit is intended to allow the compiling of native C/C++ binaries from gems on Windows, so as to aviod using precompiled windows binaries.

因为我安装了两个版本的 ruby​​,并且每个版本都需要不同的 devkit(一个用于 2x,一个用于 1x),所以我必须对 devkit 进行两次设置:

Because I've got two versions of ruby installed, and each requires a different devkit (one for 2x and one for 1x), I had to do the setup for devkit twice:

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 已设置正确地并从 HKEY_CURRENT_USER\Software\Microsoft\Command Processor 中删除任何 AutoRun 键——我从 ANSIcon 中获得了一个并适当地删除了它.

At this point I should have been able to run gem install json —platform=ruby successfully, but got the error above. After a little digging I discovered this, which advises checking that COMSPEC is set corectly and removing any AutoRun keys from HKEY_CURRENT_USER\Software\Microsoft\Command Processor – I had one from ANSIcon and duly deleted it.

不幸的是,我仍然无法安装 json gem.

Unfortunatly I was still unable to install the json gem.

然后我突然想到可能使用了错误版本的 GCC,或者没有找到.两个版本的 Devkit 带有不同版本的 gcc:

It then struck me that perhaps the wrong version of GCC was being used, or not being found. The two versions of Devkit come with different versions of 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.感谢这篇文章,看来事实并非如此:

I then wondered if pik wasn't loading the version of devtools (and therefore gcc) for the specific version of ruby that i'd picked, and was always using 1.9.3. Thanks to this article, it seems that's not the case:

> 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 可用,但它可以提供更清晰的解释)

(I don't actually have cat available on windows but it makes for a clearer explanation)

如您所见,devkit.rb 似乎正在将正确版本的 devkit 添加到路径中,这显然正在加载,因为我的错误包含临时增强 PATH 以包含 DevKit...".

As you can see, it looks like the correct version of devkit is being added to the path by devkit.rb, which is obviously being loaded because my error contains 'Temporarily enhancing PATH to include 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 的样子:

Unfortunatly the results log doesn't exactly offer much in the way of help. This is what gem_make.out looks like:

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

我认为 extconf.rb 可能会提供一些帮助,但我无法理解它:

I thought that extconf.rb might offer some help, but I can't make head nor tail of it:

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'

C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator 中的 Makefile 看起来像这样.在我看来,这个 Makefile 甚至正在被创建似乎很奇怪.

The Makefile in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator looks like this. It seems odd to me that this Makefile is even being created.

如果有更多 Windows/Ruby 经验的人可以对此有所了解,那就太棒了!

If anybody with a bit more Windows/Ruby experience can shed any light on this it would be amazing!

附注.我使用的是 Windows 7 Professional SP1

PS. I'm on Windows 7 Professional SP1

所以我想检查一下 devkit 是否使用正确的 devkit 目录大胆地增强了路径.感谢另一个 SO 问题的建议,我将 devkit 安装移到了 Ruby 目录中:

So I wanted to check that devkit was defiantly enhancing the path with the correct devkit directories. Thanks to a suggestion from another SO question, I moved the devkit installations inside the Ruby directories:

tdm devkit 现在位于 C:\Ruby193\devkit 而 mingw64 位于 C:\Ruby200\devkit.为每个 devkit 运行 ruby dk.rb install -f 后,我打开了两个 devkit.rb 文件以检查路径是否已正确更新.他们有,我更新了看跌期权,所以它应该打印临时增强 PATH 包括 DevKit for 1.9"或临时增强 PATH 包括 DevKit for 2".通过确认正在加载正确的开发包:

The tdm devkit now lives in C:\Ruby193\devkit while the mingw64 lives in C:\Ruby200\devkit. Having run ruby dk.rb install -f for each devkit, I opened up both devkit.rb files to check that the path's had been updated correctly. They had, and I updated the puts so it should print "Temporarily enhancing PATH do include DevKit for 1.9" or "Temporarily enhancing PATH do include DevKit for 2". By way of confirmation that the correct devkit is being loaded:

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

这样看起来一切正常.但是:

So that all looks like it works correctly. but:

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

这清楚地告诉我们两件事:

This clearly tells us two things:

  1. 当我使用 ruby​​ 1.9 时,正在加载其他一些 devkit.rb 文件,因为没有打印for 1.9"消息.
  2. 这不太可能是实际问题,因为两种情况下的错误都是相同的.

我将看看是否可以使用生成的 Makefile 手动构建.

I'm going to see if I can build manually using the generated Makefiles.

推荐答案

所以这不是世界上最好的答案,但我似乎偶然发现了一个解决方案.如果我设置了详细标志,一切正常:

So this isn't the best answer in the world, but I seem to have stumbled on a solution. If I set the verbose flag, everything works fine:

gem install json --platform=ruby --verbose

这里有一个日志:http://gist.github.com/dannysmith/8055495

这毫无意义 - 如果有人能解释为什么这似乎修复了错误,那就太好了.也许这是 devkit 中的一个错误?

That makes no sense - it'd be great if someone could explain why this seems to have fixed the error. Perhaps this is a bug in devkit?

这篇关于在 Windows 7 上“无法构建 gem 本机扩展"(系统找不到指定的路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆