rpc之thrift-深度调研

thrift进阶

Skip to end of metadata

  • Created by 郑方虎, last modified by Zewei1 Lu 芦泽伟 on Jul 22, 2020

Go to start of metadata

一、下载

在官方网站下载thrift 0.5.0:https://archive.apache.org/dist/incubator/thrift/0.5.0-incubating/,选择thrift-0.5.0.tar.gz 进行下载;

二、保存并解压

放到本地目录,比如/tmp,然后解压:tar -xzvf thrift0.5.0.tar.gz;

进入thrift-0.5.0;

三、安装依赖

按照官方网站上的说明(https://thrift.apache.org/docs/install/debian),安装所需依赖:

|

sudo apt-get ``install automake bison flex g++ git libboost-all-dev libevent-dev libssl-dev libtool ``make pkg-config

|

 四、编译前配置

|

.``/configure --with-cpp=no --with-python=no --with-php=no --with-ruby=no --with-csharp=no --with-erlang=no --with-perl=no --with-php_extension=no --with-haskell=no

|

由于我们只需要java版本,所以取消对其他语言的支持,如果加入其他语言支持的话,因为这个thrift的版本比较低,估计还要另一番折腾>_<

五、编译

执行make命令。

在我的机器上(Ubuntu 18.04 64-bit, gcc version 7.4.0, GNU Make 4.1)编译的时候会报错:

|

src``/generate/t_rb_generator``.cc: In member ``function ‘virtual void t_rb_generator::generate_enum(t_enum*)’:

src``/generate/t_rb_generator``.cc:318:11: error: operands to ?: have different types ‘bool’ and ‘std::basic_ostream

first ? first = ``false : f_types_ << ``", "``;

~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src``/generate/t_rb_generator``.cc:328:11: error: operands to ?: have different types ‘bool’ and ‘std::basic_ostream

first ? first = ``false : f_types_ << ``", "``;

~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Makefile:693: recipe ``for target ``'thrift-t_rb_generator.o' failed

make``[3]: *** [thrift-t_rb_generator.o] Error 1

make``[3]: 离开目录“``/tmp/thrift-0``.5.0``/compiler/cpp``”

Makefile:393: recipe ``for target ``'all' failed

make``[2]: *** [all] Error 2

make``[2]: 离开目录“``/tmp/thrift-0``.5.0``/compiler/cpp``”

Makefile:379: recipe ``for target ``'all-recursive' failed

make``[1]: *** [all-recursive] Error 1

make``[1]: 离开目录“``/tmp/thrift-0``.5.0”

Makefile:308: recipe ``for target ``'all' failed

make``: *** [all] Error 2

|

解决方法:

打开./compiler/cpp/src/generate/t_rb_generator.cc 这个文件,找到第318行:

|

318

|

first ? first = ``false : f_types_ << ``", "``;

|

注释掉这一行,修改为:

|

if``(first) {

first = ``false``;

} ``else {

f_types_ << ``", "``;

}

|

找到第328行,和318行一样的内容,做出同样的修改,修改后的文件是这样子的:

[图片上传失败...(image-e94db2-1635842878612)]

保存文件,重新make,成功后的输出类似如下:

|

BUILD SUCCESSFUL

Total ``time``: 7 seconds

make``[3]: 离开目录“``/tmp/thrift-0``.5.0``/lib/java``”

make``[3]: 进入目录“``/tmp/thrift-0``.5.0``/lib``”

make``[3]: 对“all-am”无需做任何事。

make``[3]: 离开目录“``/tmp/thrift-0``.5.0``/lib``”

make``[2]: 离开目录“``/tmp/thrift-0``.5.0``/lib``”

Making all ``in test

make``[2]: 进入目录“``/tmp/thrift-0``.5.0``/test``”

make``[3]: 进入目录“``/tmp/thrift-0``.5.0``/test``”

make``[3]: 对“all-am”无需做任何事。

make``[3]: 离开目录“``/tmp/thrift-0``.5.0``/test``”

make``[2]: 离开目录“``/tmp/thrift-0``.5.0``/test``”

make``[2]: 进入目录“``/tmp/thrift-0``.5.0”

make``[2]: 离开目录“``/tmp/thrift-0``.5.0”

make``[1]: 离开目录“``/tmp/thrift-0``.5.0”

|

六、安装

找到./compiler/cpp/thrift这个文件,复制到/usr/bin/目录下,完成安装。验证版本:thrift -version:

|

>> thrift -version

Thrift version 0.5.0

|

你可能感兴趣的:(rpc之thrift-深度调研)