1、安装boost、thrfit
2、生成gen-cpp
3、编译其中的server,方法为:
(1)、直接使用g++编译
g++ -o server HelloWorld.cpp helloworld_constants.cpp helloworld_types.cpp HelloWorld_server.skeleton.cpp -I/usr/local/include/thrift -L/usr/local/lib -lthfit
运行生成server,有可能出现找不到链接库的情况
./server
./server:error while loading shared libraries: libthrift-0.10.0.so: cannot open shared object file: No such file or directory
解决方法:
在/etc/ld.so.conf下面添加一行/usr/local/lib,即libthrfit-0.10.0.so所在的路径。
ldconfig更新配置即可。
对于使用g++编译的方法,可以写一个shell脚本,这样就不用每次都在命令行输入了。
脚本代码:
#!/bin/bash name=server#注意没有空格 echo $name rm $name g++ -o $name HelloWorld.cpp helloworld_constants.cpp helloworld_types.cpp HelloWorld_server.skeleton.cpp -I/usr/local/include/thrift -L/usr/local/lib -lthfit
(2)、使用Qt编译
如果系统装了Qt,可以利用该开发工具进行相关开发
首先通过qmake -project或自己创建.pro文件,在其中添加依赖文件:
INCLUDEPATH += -I/usr/local/include/thrift
LIBS += -L/usr/local/lib -lthrift