.

Monday, July 12, 2010

Thrift Installation with Ruby 1.9.1 on Windows

When I try the command "gem install thrift" with Ruby 1.9.1, I got a compilation error with something related to a C function "strlcpy()".

Then I searched the web. It seems I am not alone and the community know it.

However I do not want to wait for official update, I want to try Cassandra and Thrift is a dependency I have to use now.

So, read on if you want a dirty fix.

Start command line console and run:

$ gem install thrift

If you got the error with "strlcpy", you should have thrift code downloaded in your ruby gems folder.

It is "C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0" for my computer on Windows.

$ cd C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0\ext

If you are using linux, check the lib/.../ext folder.

Open "extconf.rb" and "struct.c" with a text editor. Comment out HAVE_STRLCPY in "struct.c" like this:

/*
#ifndef HAVE_STRLCPY

static

size_t

strlcpy (char *dst, const char *src, size_t dst_sz)

{ ...

}

#endif
*/

Comment out have_func line in "extconf.rb" like this:

# have_func("strlcpy", "string.h")

Then run:

$ cd C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0

$ ruby setup.rb

$ gem spec C:\Ruby\lib\ruby\gems\1.9.1\cache\thrift-0.2.0.gem --ruby > \

C:\Ruby\lib\ruby\gems\1.9.1\specifications\thrift-0.2.0.gemspec

$ gem list

You should see "thrift (0.2.0)" is in your local installed gem list.

2 comments:

Saravanan said...

I'm trying to installing thrift gem 0.6.0 on windows with ruby 1.8.7. I got the same error(strlcpy) then I've followed your steps. when I execute the $ ruby setup.rb I got the following error.

C:\Ruby187\lib\ruby\gems\1.8\gems\thrift-0.6.0>ruby setup.rb
---> lib
---> lib/thrift
---> lib/thrift/core_ext
<--- lib/thrift/core_ext
---> lib/thrift/protocol
<--- lib/thrift/protocol
---> lib/thrift/serializer
<--- lib/thrift/serializer
---> lib/thrift/server
<--- lib/thrift/server
---> lib/thrift/transport
<--- lib/thrift/transport
<--- lib/thrift
<--- lib
---> ext
C:/Ruby187/bin/ruby.exe C:/Ruby187/lib/ruby/gems/1.8/gems/thrift-0.6.0/ext/extconf.rb
creating Makefile
<--- ext
---> lib
---> lib/thrift
---> lib/thrift/core_ext
<--- lib/thrift/core_ext
---> lib/thrift/protocol
<--- lib/thrift/protocol
---> lib/thrift/serializer
<--- lib/thrift/serializer
---> lib/thrift/server
<--- lib/thrift/server
---> lib/thrift/transport
<--- lib/thrift/transport
<--- lib/thrift
<--- lib
---> ext
make
setup.rb:655:in `command': system("make") failed (RuntimeError)
from setup.rb:664:in `make'
from setup.rb:1258:in `setup_dir_ext'
from setup.rb:1532:in `__send__'
from setup.rb:1532:in `traverse'
from setup.rb:1549:in `dive_into'
from setup.rb:1530:in `traverse'
from setup.rb:1524:in `exec_task_traverse'
from setup.rb:1519:in `each'
from setup.rb:1519:in `exec_task_traverse'
from setup.rb:1246:in `exec_setup'
from setup.rb:996:in `exec_setup'
from setup.rb:813:in `invoke'
from setup.rb:773:in `invoke'
from setup.rb:1578

byungjin said...

I used that step using ruby 1.9.1 version.
I think the case of 1.8.7 version can be different.
To use Ruby perfectly, you should use linux (ubuntu, fedora) or MacOS.
Unfortunately, Windows is not good for ruby programming.
Thank you.

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Macys Printable Coupons