参考链接:
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
运行示例效果截图:
UserStorage.h
UserStorage_server.skeleton.cpp
demo_constants.cpp
demo_constants.h
demo_types.cpp
demo_types.h
// You should copy it to another filename to avoid overwriting it.
#include <protocol/TBinaryProtocol.h>
#include <server/TSimpleServer.h>
#include <transport/TServerSocket.h>
#include <transport/TBufferTransports.h>
#include <map>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
public:
UserStorageHandler() {
// Your initialization goes here
}
// Your implementation goes here
printf("store\n");
}
// Your implementation goes here
printf("getUser\n");
}
};
int port = 9090;
shared_ptr<UserStorageHandler> handler(new UserStorageHandler());
shared_ptr<TProcessor> processor(new UserStorageProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
server.serve();
return 0;
}
3.运行./CppServer和./CppClient时错误解决,error:./CppServer: error while loading shared libraries: libthrift-1.0.0-dev.so: cannot open shared object file: No such file or directory
解决步骤:
1、使用find命令查找缺失的libthrift-1.0.0-dev.so共享库文件所在位置:find /usr/local/ -name "libthrift-1.0.0*"
2、将找到的目录位置写入 /etc/ld.so.conf 配置文件,这个文件记录了编译时使用的动态链接库的路径,使用命令:sudo vim /etc/ld.so.conf ,在末尾增加报错文件的路径
3、然后使用ldconfig命令,使配置生效。
4.再运行测试程序正常