thrift 学习日记一

Apache Thrift 学习日记

开始正式学习thrift,今天是第一天,先看看官网文档 http://thrift.apache.org/

引用一段介绍

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

按照官网步骤,我们开始thrift之旅

  • 下载
  • 编译并安装 Apache Thrift compiler
  • 学习.thrift 文件

1. 先去下载thrift

http://thrift.apache.org/download
下载的版本是0.10.0

2. 接下来,开始学习如何编译并安装 Apache Thrift compiler

因为使用的是macbook,所以参考的 http://thrift.apache.org/docs/install/os_x 进行环境准备。
使用的boost版本是1.65.1,安装时间比较长,预计30分钟
libevent版本是2.1.8-stable(需要先安装openssl,见 遇到的问题 #1 #2)
最后编译安装Apache Thrift compiler(需要先安装Bison和ant,见 遇到的问题 #3 #4)
安装成功(最后,记得执行make命令):

thrift 0.10.0

Building Plugin Support ...... : yes
Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : yes
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : yes
Building PHP Library ......... : yes
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : yes
Building Lua Library ......... : no

C++ Library:
   Build TZlibTransport ...... : yes
   Build TNonblockingServer .. : yes
   Build TQTcpServer (Qt4) .... : no
   Build TQTcpServer (Qt5) .... : no

Java Library:
   Using javac ............... : javac
   Using java ................ : java
   Using ant ................. : /usr/local/bin/ant

C# Library:
   Using .NET 3.5 ............ : yes

Python Library:
   Using Python .............. : /usr/bin/python

PHP Library:
   Using php-config .......... :

Perl Library:
   Using Perl ................ : /usr/bin/perl

NodeJS Library:
   Using NodeJS .............. : /usr/local/bin/node
   Using NodeJS version....... : v4.4.4

3. 总算安装完啦,可以开始学习 thrift 了

遇到的问题

#1. 编译libevent时,提示找不到openssl,这个是因为没有安装openssl(安装完后继续编译libevent),下面给出安装openssl步骤:

# darwin64-x86_64-cc 这个编译选项可以不加
# 但在执行的过程中提示操作系统是64位的,如果要编译支持64位的库,可以添加这个编译选项
sudo ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl
make
make install
openssl version

#2. 编译libevent时,安装了openssl,提示找不到 'openssl/ssl.h' 文件
执行configure脚本时,指定寻找路径:

./configure --prefix=/usr/local \
CPPFLAGS="-I/usr/local/openssl/include" \
LDFLAGS="-I/usr/local/openssl/lib"

#3. 安装thrift时,报错:Bison version 2.5 or higher must be installed on the system!
安装新版的bison

# 安装最新 bison
brew install bison

# 安装完成
$ brew list bison
/usr/local/Cellar/bison/3.0.4/bin/bison
/usr/local/Cellar/bison/3.0.4/bin/yacc
/usr/local/Cellar/bison/3.0.4/lib/liby.a
/usr/local/Cellar/bison/3.0.4/share/aclocal/bison-i18n.m4
/usr/local/Cellar/bison/3.0.4/share/bison/ (23 files)
/usr/local/Cellar/bison/3.0.4/share/doc/ (14 files)
/usr/local/Cellar/bison/3.0.4/share/info/bison.info
/usr/local/Cellar/bison/3.0.4/share/man/ (2 files)
已经安装3.0.4版本

但是安装thrift,仍然报错:Bison version 2.5 or higher must be installed on the system!

经查是使用了xcode自带的bison,路径 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

解决办法:

# 首先将bison改名
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
sudo mv bison bison111

# 然后新版本的bison复制到路径下
sudo cp /usr/local/Cellar/bison/3.0.4/bin/bison  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

# 再次安装thrift,安装成功。

# 再还原xcode中的bison
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
sudo rm bison
sudo mv bison111 bison

#4. Building Java Support ... no
参考的这篇文章(http://blog.csdn.net/agul_/article/details/50998187),不过先安装的版本是最新版本1.10.1,结果还是不行,看日志发现了这段

configure:18828: checking for ant
configure:18846: found /usr/local/bin/ant
configure:18858: result: /usr/local/bin/ant
configure:18867: checking for ant version > 1.7
configure:18874: result: no

所以怀疑这个判断版本的逻辑有问题,估计是按字符串比较大小的,所以重新下载了ant 1.9.9 版本,并重新安装了 Apache Thrift compiler,成功!!!

PS: 在解决这个问题的时候,又要回过去解决 "Bison version 2.5 or higher must be installed on the system!" ~~~ TAT
另外,因OSX升级后,/usr/bin sudo都没有写权限了,所以ant改放到/usr/local/bin中

#5. 'boost/utility/enable_if.hpp' 找不到

./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local \
CPPFLAGS="-I/usr/local/include" \
LDFLAGS="-I/usr/local/lib"

#6. gmcs不存在,这个是mono,c#编译器

cd /usr/local/bin
ln -s -f /Library/Frameworks/Mono.framework/Versions/Current/Commands/mcs

# 然后重新执行configure命令,之后make
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335

推荐阅读更多精彩内容