'在Windows 7上无法构建gem native extension'(系统找不到指定的路径)

问题描述 投票:20回答:7

问题简而言之

我在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 Installer进入C:/Ruby193
  • Ruby 2.0.0p353与Ruby Installer进入C:/Ruby200
  • Devkit DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe(红宝石1x)提取到C:/Ruby193-devkit
  • Devkit DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe(红宝石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:/binC:/Ruby193/bin在路上。这意味着当我启动shell时默认加载ruby 1.9.3并且我可以使用pik use 2.0.0p353成功切换到2.0.0。换句话说,pik工作得很好。

Devkit is intended允许从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,但是得到了上面的错误。经过一些挖掘I discovered this,建议检查COMSPEC是否已设置核心并从HKEY_CURRENT_USER\Software\Microsoft\Command Processor删除任何AutoRun密钥 - 我有一个来自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。感谢this article,似乎并非如此:

> 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'

(我实际上并没有在窗户上使用猫,但它可以提供更清晰的解释)

正如您所看到的,看起来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'

C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator looks like this中的Makefile。对我来说这个Makefile甚至被创建似乎很奇怪。

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

PS。我在Windows 7 Professional SP1上

经过一番挖掘后更新

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

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”。通过确认正在加载正确的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

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

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

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

ruby windows pik
7个回答
11
投票

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

gem install json --platform=ruby --verbose

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

这没有任何意义 - 如果有人能够解释为什么这似乎解决了错误,那就太好了。也许这是devkit中的一个错误?


7
投票

尝试在管理员模式下运行命令提示符经过7到10个小时,我想出来了......


7
投票

我安装了版本1.8.1的gem json,但是我无法使用json 1.6.1来解决这个问题

gem install json --platform=ruby --verbose

所以,我从这里尝试https://github.com/oneclick/rubyinstaller/issues/184

gem update --system 2.0.3

在那之后

gem install json -v 1.6.1 --platform=ruby --verbose

它为Win 7(64位)机器解决了json 1.6.1特有的问题


0
投票

在Windows上安装32位版本...

ver
windows 6.1.76011

64位给出了有关makefile和标头的错误消息。尝试了所有其他建议,包括关于COMSPEC和注册表的rubyinstaller上的建议,将gcc添加到路径等等。有些宝石会安装,但git_fame和json不需要编译。

编辑:看起来git_fame使用mimer_plus。 mimer_plus假定使用gnu工具(unix工具)。看起来你需要先安装mingw。在rubyinstaller页面上没有明确指出。


0
投票

我有同样的问题。我使用powershell来检查我的路径

ps> $ s = $ env:path

ps> $ s.split(“{;}”)

果然我的红宝石mingw不在路上。我在路径中有ruby \ bin但是mingw \ bin位于不同的文件夹下。我进入我的环境路径并添加它,我的安装工作。


0
投票

确保您安装的ruby版本(32位或64位)与DevKit版本匹配。他们都必须是32或64,这是我遇到的问题。可能不是这里的确切问题,但我想我会把它扔出去。这是一篇值得一试的帖子:

Rails on windows - install issue


0
投票

我是如何修理它的:

  1. https://rubyinstaller.org/downloads/下载了最新的ruby安装程序
  2. 按照提示安装依赖项,然后运行安装程序。
  3. 重新启动了我的电脑。
  4. 在我的PATH中添加了ruby / bin目录。
© www.soinside.com 2019 - 2024. All rights reserved.