Thrift CPP例子 - ggg Freak - 博客频道 - CSDN.NET

Thrift CPP例子 - ggg Freak - 博客频道 - CSDN.NET

Thrift CPP例子

分类: linux 1152人阅读 评论(1) 收藏 举报

 

tutorial 最简单例子

 

 

 

1.安装成功后进入 tutorial 目录 运行 thrift -r --gen cpp tutorial.thrift  会在gen-cpp目录下生成一些文件

2. 进入 cpp 目录 ,然后直接进行  make

3.  编译成功的会生成 CppClient 和 CppServer

 

 

 

other... 

 

  1.  新建 test.thrift 文件,内容如下

    [c-sharp] view plain copy print ?
    1. namespace cpp Test  
    2.   
    3. service Something {  
    4.     i32 ping()  
    5. }  
    namespace cpp Test service Something { i32 ping() }
  2. 运行 thrift --gen cpp test.thrift 进行生成c++格式的代码,可以在当前 代码会生成在 gen-cpp 目录
  3. 进入 gen-cpp 目录,复制一份  cp Something_server.skeleton.cpp Something_server.cp
  4. 添加一些环境变量,用于指定编译时的库文件路径,运行
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:/usr/lib/
    可以把该命令加到 ~/.bashrc 文件里,以便每次登录自动运行
  5. 快速编译  g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something
    在编译时如提示存在多个 main() ,按提示注释掉 Something_server.skeleton.cpp  里的 main() 代码
  6. 如果要进行手工编译如下:

    [c-sharp] view plain copy print ?
    1. g++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o  
    2. g++ -Wall -I/usr/local/include/thrift -c Something_server.cpp -o server.o  
    3. g++ -Wall -I/usr/local/include/thrift -c test_constants.cpp -o constants.o  
    4. g++ -Wall -I/usr/local/include/thrift -c test_types.cpp -o types.o  
    5.   
    6. 然后进行链接   
    7. ld -L/usr/local/lib -lthrift *.o -o Something_server   
    g++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o g++ -Wall -I/usr/local/include/thrift -c Something_server.cpp -o server.o g++ -Wall -I/usr/local/include/thrift -c test_constants.cpp -o constants.o g++ -Wall -I/usr/local/include/thrift -c test_types.cpp -o types.o 然后进行链接 ld -L/usr/local/lib -lthrift *.o -o Something_server
  7. 运行 编译后生成的 ./something

 

 

 

参考

ThriftUsageC++

http://wiki.apache.org/thrift/ThriftUsageC%2B%2B

 

 

error while loading shared libraries

 

http://hi.baidu.com/%C6%AE%BA%F6%B5%C4%C3%E6%B0%FC%CA%F7/blog/item/72daf0508b05271f367abe83.html

posted on 2013-01-21 22:04  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2013/01/21/2870455.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值