Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

ruby - 'Failed to build gem native extension' on Windows 7 (The system cannot find the path specified)

The problem in short

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

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

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.

My PATH looks like this:

PATH=C:in;C:Ruby193in;C:windows;C:windowssystem32;C:windowssystem32Wbem;c:Program Files (x86)Microsoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100DTSBinn;C:Program Files (x86)Common FilesRoxio SharedDLLShared;C:Program FilesJavajdk1.6.0_33in;C:Program Files (x86)Common FilesAppleMobile Device Support;C:Program Files (x86)Common FilesAppleApple Application Support;C:Program Files (x86)QuickTimeQTSystem;C:Program FilesTortoiseSVNin;C:/inpath;C:Program Files (x86)WinMerge;C:ChromeDriver;C:Program FilesWIDCOMMBluetooth Software;C:Program FilesWIDCOMMBluetooth Softwaresyswow64

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 is intended to allow the compiling of native C/C++ binaries from gems on Windows, so as to aviod using precompiled windows binaries.

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

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_USERSoftwareMicrosoftCommand Processor – I had one from ANSIcon and duly deleted it.

Unfortunatly I was still unable to install the json gem.

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-devkitmingwingcc —version
gcc (tdm-1) 4.5.2

> C:Ruby200-devkit-x32mingwingcc —version
gcc (rubenv-4.7.2-release) 4.7.2

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:Ruby193in
uby.exe

> cat C:Ruby193lib
ubysite_rubydevkit.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:Ruby200in
uby.exe

> cat C:Ruby200lib
ubysite_rubydevkit.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'

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

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

Back to the original error

It was:

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

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

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'

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.

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

PS. I'm on Windows 7 Professional SP1

Update after some more digging

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:

The tdm devkit now lives in C:Ruby193devkit while the mingw64 lives in C:Ruby200devkit. 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:Ruby193devkitin;C:Ruby193devkitmingwin;C:in;C:Ruby193in;C:windows;C:windowssystem32;C:windowssystem32Wbem;c:Program Files (x86)
Microsoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100DTSBinn;C:Pro
gram Files (x86)Common FilesRoxio SharedDLLShared;C:Program FilesJavajdk1.6.0_33in;C:Program Files (x86)Common FilesAppleMobile Device Su
pport;C:Program Files (x86)Common FilesAppleApple Application Support;C:Program Files (x86)QuickTimeQTSystem;C:Program FilesTortoiseSVNin
;C:/inpath;C:Program Files (x86)WinMerge;C:ChromeDriver;C:Program FilesWIDCOMMBluetooth Software;C:Program FilesWIDCOMMBluetooth Softwaresy
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:Ruby200devkitin;C:Ruby200devkitmingwin;C:in;C:Ruby200in;C:windows;C:windowssystem32;C:windowssystem32Wbem;c:Program Files (x86)
Microsoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100DTSBinn;C:Pro
gram Files (x86)Common FilesRoxio SharedDLLShared;C:Program FilesJavajdk1.6.0_33in;C:Program Files (x86)Common FilesAppleMobile Device Su
pport;C:Program Files (x86)Common FilesAppleApple Application Support;C:Program Files (x86)QuickTimeQTSystem;C:Program FilesTortoiseSVNin
;C:/inpath;C:Program Files (x86)WinMerge;C:ChromeDriver;C:Program FilesWIDCOMMBluetooth Software;C:Program FilesWIDCOMMBluetooth Softwaresy
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. Some other devkit.rb file is being loaded when I'm using ruby 1.9, as the 'for 1.9' message isn't being printed.
  2. This is unlikely to be the actual problem, as the error is identical in either case.

I'm going to see if I can build manually using


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

There's a log here: http://gist.github.com/dannysmith/8055495

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...