易截截图软件、单文件、免安装、纯绿色、仅160KB

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 线程的性能测试

在使用中ruby的过程中难免会遇到提高性能的问题,由此便想起了ruby线程。但是我在使用中却发现ruby的线程却不能提高性能。我写了以下代码,做了些简单测试。
代码
# -*- coding: GB2312 -*-
require 'date'
# 使用线程,线程的处理代码里没有sleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
......

升级到snow leopard后ruby的问题

1. ruby已成为1.87 2. 必须先安装安装光盘里的新的xcode,在"optional"目录里 3. 可能需要重新安装macport http://trac.macports.org/wiki/Migration 4. 或者升级macport http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard $ sudo port selfupdate
$ sudo port sync
$ sudo port upgrade --force insta ......

交互式 Ruby Shell irb

irb 是从命令行运行的
irb 的命令行选项(摘自 Porgramming Ruby 第二版)
-f
禁止读取~/.irbrc Suppress reading ~/.irbrc.
-m
数学模式(支持分数和矩阵) Math mode (fraction and matrix support is available).
-d
设置#DEBUG为true(同ruby -d一样)  Set $DEBUG to true (same as ``ruby -d'').
-r lo ......

Ruby 命令行 常用命令

从命令行启动Ruby解释器时,你不仅可以提供程序文件的名字,而且可以提供一个或多个命令行开关。你选择的开关指示解释器以一种特定的方式运转,并且/或者执行特定的操作。
Ruby命令行开关有20多个,其中有些很少使用,有些则每天被很多Ruby程序员使用。在这里我们将再看几个最常用的。(你已经看到过其中的两个,-c和&ndas ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号