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 文件,内容如下

    1. namespace cpp Test  
    2.   
    3. service Something {  
    4.     i32 ping()  
    5. }  
  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. 如果要进行手工编译如下:

    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   
  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

原文地址:https://www.cnblogs.com/lexus/p/2870455.html