Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:\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

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_USER\Software\Microsoft\Command 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-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

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'

(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:\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. 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 the generated Makefiles.

like image 525
dannysmith Avatar asked Dec 19 '13 18:12

dannysmith


2 Answers

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?

like image 74
dannysmith Avatar answered Oct 25 '22 21:10

dannysmith


Try running command prompt in admin mode. After like 7-10 hours I figured this out...

like image 22
obesechicken13 Avatar answered Oct 25 '22 21:10

obesechicken13