thrift实现一个C++实例遇到的问题

问题1:Building C++ Library ......... : no
源码安装boost库,在thrift安装中configure命令时,会出现上述错误,最后根据下面链接用apt命令安装boost库就没有这个问题了

安装:http://www.tuicool.com/articles/m2EjQn

不是说源码安装boost库不行,可能是哪里没有设置好。


问题2:编译代码出现很多形如undefined reference to `apache::thrift::的错误

实例:http://blog.csdn.net/hbuxiaoshe/article/details/6558391

最后发现:-lthrift一定要放在后面

参考:http://my.oschina.net/zmlblog/blog/177245 

例:

服务端编译:

g++ -g -I/usr/local/include/thrift -L/usr/local/lib/ Serv.cpp student_types.cpp student_constants.cpp Serv_server.skeleton.cpp -o server -lthrift

客户端编译:

g++ -g -I/usr/local/include/thrift -L/usr/local/lib/ -lm -pthread -lz -lrt -lssl Serv.cpp student_types.cpp student_constants.cpp client.cpp -o client -lthrift


最后,有一个很好的thrift C++实例:

http://blog.csdn.net/linyanwen99/article/details/8281508



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Thrift一个高效的跨语言 RPC 框架,它支持多种编程语言,包括 C++, Java, Python, Ruby, PHP 等。下面是一个简单的 Thrift 实例,展示了如何使用 Thrift 进行跨语言通信: 1. 编写 Thrift IDL 文件 定义一个 Thrift 接口,使用 Thrift IDL 语言编写一个服务接口文件,例如 Example.thrift: ``` namespace java com.example namespace py example service ExampleService { string ping(1: string message) } ``` 2. 生成代码 使用 Thrift 编译器将 Thrift IDL 文件编译成代码,例如: ``` thrift --gen java Example.thrift thrift --gen py Example.thrift ``` 将会生成 Java 和 Python 的代码文件,可以根据需要进行使用。 3. 实现服务端 使用生成的代码实现服务端,例如 Java 语言: ```java public class ExampleHandler implements ExampleService.Iface { @Override public String ping(String message) throws TException { return "Pong: " + message; } } public static void main(String[] args) throws Exception { TServerTransport serverTransport = new TServerSocket(9090); ExampleService.Processor<ExampleHandler> processor = new ExampleService.Processor<>(new ExampleHandler()); TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); System.out.println("Starting the server..."); server.serve(); } ``` 4. 实现客户端 使用生成的代码实现客户端,例如 Python 语言: ```python transport = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = ExampleService.Client(protocol) transport.open() response = client.ping("Hello, world!") print(response) transport.close() ``` 以上就是一个简单的 Thrift 实例,展示了如何使用 Thrift 进行跨语言通信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值