OK, so I am writing this post after a whole day spent in effort to get Thrift working on Ruby 1.9.2, so that I can run the Cassandra gem. Now what I always expected out of Gem system is breezy a experience. But today it was really rough. Now some people and Google results suggest that its due to my Ubuntu 11.10 distribution, but if its due to Ubuntu guys why ain’t anybody reported on Ubuntu bug tracking! Some people say its due to Ruby, and there are lots of endless discussions with no conclusions.
Anyways I don’t want any of you to waste your time on the same exercise that I did today and waste a Sunday! Hopefully this post will help you fix issue. So here we go if you right now do gem install thrift on your system and you get error like
…(Some compile commands)
ruby/missing.h:157:20: note: previous declaration of ‘strlcpy’ was here
make: *** [struct.o] Error 1”
You are victim of RRT (Really Really Trash)! Here is how to fix it. First download the original Thrift 0.7.0 source code distribution from apache’s site. Extract, configure, and install it with your Ruby 1.9.2 activated (in case you use RVM). Here are commands to do so:
rvm 1.9.2
tar vxzf [your thrift archive].tar.gz
cd thrift-0.7.0
./configure
make && make install
Be sure you have ruby development library installed, and things will go fine. Next just to make sure you get the native thrift client for your activated Ruby, inside thrift source directory go to lib/rb (cd lib/rb) and run rvm 1.9.2 && ruby setup.rb. In case of Ruby 1.9.3, (Running ruby setup.rb) I encountered same as before error saying “struct.c:28:1: error: static declaration of ‘strlcpy’ follows non-static declaration”, to fix this error just open up the ext/struct.c (inside the same lib/rb directory) and remove the static keyword from line 26. Once you have done that you can now install native client of thrift. Lets install the gem now!
First download the thrift gem from here. Make sure its version is 0.7.0 (matches thrift protocol you compiled). Once done do gem unpack thrift-0.7.0 to unpack the gem contents into thrift-0.7.0 directory. Go to thrift-0.7.0 director and you will find similar structure as lib/rb in thrift source code (not exactly similar but I am mentioning ext directory specifically). Again open up the same file (struct.c) and remove the static keyword from line 26. Running ruby setup.rb inside gem directory should be error free now. Since I am using bundle to do package management a one liner in Gemfile should do the job for me.
gem “thrift”, :path => ‘thrift-0.7.0’ #path to modified gem directory
And thats about it. Launch your IRB an things should load up. Hope it saves you a day!
Design by Simon Fletcher. Powered by Tumblr.
© Copyright 2010