Tuesday, February 5, 2008

gem install ruby-debug fails in windows

While trying to install ruby-debug in windows, I ran into the following issues
d:\tmp>gem install ruby-debug
Building native extensions. This could take a while...
ERROR: Error installing ruby-debug:
ERROR: Failed to build gem native extension.

C:/ruby/bin/ruby.exe extconf.rb install ruby-debug
creating Makefile

nmake
'nmake' is not recognized as an internal or external command,
operable program or batch file.


Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/
ruby-debug-base-0.10.0 for inspection.
Results logged to C:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-base-0.10.0/
ext/gem_make.out
This is obvious - ruby-debug is trying to build and install a native extension and fails because a default command prompt in windows does not include the compiler environment.

You need Visual Studio 2005 command prompt. It can be found under Start->All Programs->Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt. I manually invoked nmake.exe (make utility that ships with VS) on the gem generated Makefile.

Assuming you have installed ruby under C:\ruby, here's the log

Setting environment for using Microsoft Visual Studio 2005 x86 tools.

C:\Program Files\Microsoft Visual Studio 8\VC>gem install ruby-debug
Building native extensions. This could take a while...
Successfully installed ruby-debug-base-0.10.0
Successfully installed ruby-debug-0.10.0
2 gems installed
Installing ri documentation for ruby-debug-base-0.10.0...
Installing ri documentation for ruby-debug-0.10.0...
Installing RDoc documentation for ruby-debug-base-0.10.0...
Installing RDoc documentation for ruby-debug-0.10.0...

At this point, I am ready to test it as follows
C:\Program Files\Microsoft Visual Studio 8\VC>irb -rruby-debug

But alas, I get a runtime error (R6034) as follows



So I hit Google and after some research, I realize that the manifest (which is a new concept introduced in VC++ post VC6) is not embedded into the dll (or ruby_debug.so in this case) by default when you build from command line. This is easy enough - using mt.exe I do the following

C:\Program Files\Microsoft Visual Studio 8\VC>cd C:\ruby\lib\ruby\gems\1.8\gems\ruby-debug-base-0.10.0\ext

C:\ruby\lib\ruby\gems\1.8\gems\ruby-debug-base-0.10.0\ext>mt.exe -manifest ruby_debug.so.manifest -outputresource:ruby_debug.so;2
Microsoft (R) Manifest Tool version 5.2.3790.2014
Copyright (c) Microsoft Corporation 2005.
All rights reserved.
Don't forget to install the brand new binary as
C:\ruby\lib\ruby\gems\1.8\gems\ruby-debug-base-0.10.0\ext>nmake install

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

install -c -p -m 0755 ruby_debug.so C:\ruby\lib\ruby\gems\1.8\gems\ruby-debug-base-0.10.0\lib
Now I am back in business as seen below
C:\ruby\lib\ruby\gems\1.8\gems\ruby-debug-base-0.10.0\ext>irb -rruby-debug
irb(main):001:0>
I have included some helpful links on this topic
http://archives.windowshpc.net/blogs/dev_gen/archive/2006/10/23/671.aspx
http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=94312&SiteID=1

It would be nice if the gem itself includes mt.exe step on win32 builds. Please feel free to add if there is a better way or even another way.

4 comments:

Luis said...

Wow, you definitely took the most complicated path!

Mixing CRT libraries is not advised (Ruby is built against MSVCRT while the extension you built uses MSVCR80)

Using updated Ruby version from RubyInstaller project you could have followed the tutorials from here:

http://wiki.github.com/oneclick/rubyinstaller/tutorials

http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/

Hope that helps.

Ryan Shillington said...

You don't need to install Visual Studio. All you need to do is install devkit (http://wiki.github.com/oneclick/rubyinstaller/development-kit) and then 'gem install ruby-debug' and everything will work fine.

Kishore reddy said...

Thanks Rayan

This worked for me. some more easy steps to follow to complete the work.

1. download dev kit from https://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

2. click the exe and extract to a directory say DevKit

3. open command prompt and goto the DevKit directory

run the following ruby commands
4. ruby dk.rb init to generate the config.yml

5.ruby dk.rb install

6.now try to install the gems which failed earlier.

Unknown said...

From last two hours I am searching for the tool which can fix this runtime error r6034 easily and also permanently because this error has irritated me a lot, unable to start my PC properly, wherever I start my PC then I receive this runtime error message. When I got this third party reaper tools then I have easily fixed this runtime error r6034.