Fix Thrift 0.2.0 Installation with Ruby 1.9.1
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.
Ïà¹ØÎĵµ£º
½ñÌì°ÑRuby Shoes´ò°üµÄ³ÌÐò¸´ÖƵ½Ã»Óа²×°Ruby ShoesµÄ»úÆ÷ÉÏ£¬·¢ÏÖËü»¹Ï²»ÁËRuby ShoesµÄ»·¾³°ü¡£
ÕâÈÃÎҸоõºÜ¾ÚÉ¥£¬ºÃ²»ÈÝÒ×ÈëÃÅÁËÒ»ÃÅÓïÑÔ£¬È´ÓöÉÏÁËÎÞ·¨²¿ÊðµÄÎÊÌâ¡£
ÉõÖÁ£¬ÎÒºóÀ´ÏëÒª°ÑÔËÐл·¾³Ç¶Èëµ½Ruby ShoesÖУ¬¶¼Ã»Äܹ»×öµ½¡£
ÕâÑùµÄÎÊÌâÕæÊÇÈÃÎҸоõµ½¶ÔShoesµÄʧÍû¡£
²»¹ý»¹ºÃ£¬³öÁËRuby Shoes£¬»¹Óкܶ ......
ÈýÕßÖ®¼äÇø±ð²¢²»ÏñÄãÏëµÄÄÇôÄÑ£¬Ò²²»»áÏñÓÐЩÎÄÕÂдµÄÄÇô³¤¡£Í¦¼òµ¥µÄ¡£
Ïà֮ͬ´¦£ºÈýÕß¾ùÔÚkernelÖж¨ÒåµÄ£¬¾ùº¬Óаüº¬½øÄ³ÎïÖ®Òâ¡£
²»Í¬Ö®´¦£º
1¡¢requre,loadÓÃÓÚÎļþ£¬Èç.rbµÈµÈ½áβµÄÎļþ¡£
2¡¢includeÔòÓÃÓÚ°üº¬Ò»¸öÎļþ(.rbµÈ½áβµÄÎļþ)ÖеÄÄ£¿é¡£
3¡¢requreÒ»°ãÇé¿öÏÂÓÃÓÚ¼ÓÔØ¿âÎļþ£¬¶øloadÔòÓÃÓÚ¼ÓÔØÅ ......
´ÓÃüÁîÐÐÆô¶¯Ruby½âÊÍÆ÷ʱ£¬Äã²»½ö¿ÉÒÔÌṩ³ÌÐòÎļþµÄÃû×Ö£¬¶øÇÒ¿ÉÒÔÌṩһ¸ö»ò¶à¸öÃüÁîÐпª¹Ø¡£ÄãÑ¡ÔñµÄ¿ª¹ØÖ¸Ê¾½âÊÍÆ÷ÒÔÒ»ÖÖÌØ¶¨µÄ·½Ê½ÔËת£¬²¢ÇÒ/»òÕßÖ´ÐÐÌØ¶¨µÄ²Ù×÷¡£
RubyÃüÁîÐпª¹ØÓÐ20¶à¸ö£¬ÆäÖÐÓÐЩºÜÉÙʹÓã¬ÓÐЩÔòÿÌì±»ºÜ¶àRuby³ÌÐòԱʹÓá£ÔÚÕâÀïÎÒÃǽ«ÔÙ¿´¼¸¸ö×î³£Óõġ££¨ÄãÒѾ¿´µ½¹ýÆäÖеÄÁ½¸ö£¬-cºÍ&ndas ......
ÎÄÕÂת×Ô http://www.ej38.com/showinfo/Ruby-140367.html
¹ý³ÌÈçÏ£º
1¡¢rubyÏÂÔØÒ»¼ü°²×°£º
http://rubyforge.org/frs/download.php/29263/ruby186-26.exe
ruby -v ÏÔʾ°æ±¾£¬°²×°³É¹¦
2¡¢ÏÂÔØrubygems°²×°£º
http://rubyforge.org/frs/download.php/60719/rubygems-1.3.5.zip
½âѹ£¬ruby setup.rb
g ......
#Ò»¡¢Ä£¿é¶¨Òå¼°ÒýÓã¬Ä£¿é¾ÍÊÇÒ»¶Î´úÂ룬ÀïÃæÓÐһЩ·½·¨·ÅÒ»Æð¡£
#¶¨ÒåÄ£¿éÓÃmodule...end ¡£Ä£¿éÓëÀà·Ç³£ÏàËÆ£¬µ«ÊÇ£º
#A) Ä£¿é²»¿ÉÒÔÓÐʵÀý¶ÔÏó£»
#B) Ä£¿é²»¿ÉÒÔÓÐ×ÓÀà¡£
include Math
puts sqrt(91);
module Me
def sqrt(a)
puts a*a;
return a*a;
end
PI=3.1415926 ......