Saturday, April 18, 2009

How to compile ruby extensions in windows with Visual Studio 2008

As it stands windows support is the black sheep in the ruby world at the moment. Since the system doesnt come out of the box with a c compiler and many gems need to be specifically compiled under windows, I found myself looking for a way to achieve the same comfort as under linux/OsX and get some fresh compiled extensions using vs2008.

Since I haven't found a complete tutorial how to do exactly that on the net here is my solution: (Notice: I only tested it with json and ferret gems)

1) Install Visual Studio 2008. You probably require the Windows SDK. I used a Visual studio Professional installation and it worked out of the box.

2) Install ruby, rubygems and so on.

3) Open the file C:\Ruby\lib\ruby\1.8\i386-mswin32\Config.h and delete the “#error MSC version unmatch" line or the complete "if" version check

4) Add to your path "c:\Program Files\Microsoft Visual Studio 9.0\VC\bin" and "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"

5) Run the vcvars32.bat file in a command prompt.

6) gem install json should now proceed happily with the build of native extensions.

Pretty easy huh? I learned to hate the lack of documentation in the ruby world. Feels more like a college open source project than a serious development environment.

2 comments:

Anonymous said...

ruby in visual studio, I got to vomit :)

Alexander Lagos said...

Igor you "Anonymous" its not Ruby IN visual studio, it's very simple: compiling ruby extensions under windows. You can do that with cygwin, mingw or visualstudio. This is not a ruby in steel alternative, its a cygwin alternative. ok?? :P