安装Thrift并写一个简单的测试程序

本文档详细介绍了在CentOS上安装Apache Thrift的步骤,并提供了一个C++ Server和C++ Client的简单示例。在运行示例时遇到的关于libthrift-1.0.0-dev.so共享库的错误,通过find命令查找文件,编辑/etc/ld.so.conf文件并使用ldconfig命令解决了问题。
摘要由CSDN通过智能技术生成

参考链接:

http://thrift.apache.org/docs/install/centos   Apache thrift官方安装步骤

http://blog.163.com/zhangjie_0303/blog/static/9908270620140311022650/  网友的示例,可以搞清楚Thrift到底能干什么


目录:

1.安装步骤

2.示例:C++Server 及 C++Client

3.运行示例时的错误解决,error:./CppServer: error while loading shared libraries: libthrift-1.0.0-dev.so: cannot open 

1.安装步骤

参考:http://thrift.apache.org/docs/install/centos   Apache thrift官方安装步骤,一步步安装即可。

2.示例:C++Server 及 C++Client

运行示例效果截图:


编辑demo.thrift文件,内容如下:
struct UserProfile{
        1:i32 id, //注意这里是逗号,而不是分号
        2:string name,
        3:string blurb
} //这里没有分号
 
service UserStorage{
        void store(1: UserProfile user), //注意这里是逗号,而不是分号
        UserProfile getUser(1: i32 uid)
}
 
运行如下命令
cloud1:~/test/thrift/demo # thrift -r --gen cpp demo.thrift 
cloud1:~/test/thrift/demo # ls
demo.thrift  gen-cpp
可以看到在当前目录下产生了一个gen-cpp的目录,该目录下即以上命令产生的文件:
UserStorage.cpp
UserStorage.h
UserStorage_server.skeleton.cpp
demo_constants.cpp
demo_constants.h
demo_types.cpp
demo_types.h

注意:在以上文件中,只有UserStorage_server.skeleton.cpp是跟业务相关的,是可以修改的,其余文件都是框架相关的。
UserStorage_server_skeleton.cpp文件内容如下:
 
// This autogenerated skeleton file illustrates how to build a server.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值