WIN7-x64 VS2008 编译libthrift

最近一两天都在研究如何在 VS2008上编译thrift的库文件 编译出来是静态库

1、所需要的文件

1)libevent-2.0.21-stable.tar.gz

编译 libthriftnb工程(非阻塞)所需要的文件

2)thrift-0.9.3.tar.gz


2、编译工程

源码工程 下载地址  http://pan.baidu.com/s/1ge4hyhX   该路径存储的是 .sln文件,打开即可



3、示例程序

hello.thrift的文件


service hello {
    void func1( )
}


1)生产目标代码

C:\Users\admin\Desktop\Hello>thrift-0.9.3.exe  --gen  cpp  hello.thrift

生产的目标文件如下图



4、VS2008创建工程进行测试

1)客户端代码

#include <transport/TSocket.h>
#include "hello.h"
#include <protocol/TBinaryProtocol.h>
#include <server/TSimpleServer.h>
#include <transport/TServerSocket.h>
#include <transport/TBufferTransports.h>
#include <string>
#pragma comment(lib, "libthrift.lib")
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;

using boost::shared_ptr;

#pragma comment(lib,"libthrift.lib")//链接库文件

int main(int argc, char** argv) {
	int port = 9090;
	shared_ptr<TTransport> socket(new TSocket("127.0.0.1", 9090));
	shared_ptr<TTransport> transport(new TBufferedTransport(socket));
	shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
    helloClient client(protocol);
	try{
		transport->open();

        client.func1();

		transport->close();
	}catch(TException& tx){
		printf("ERROR:%s\n",tx.what());
	}
	getchar();
	return 0;
}

2)服务端代码

hello_server.skeleton.cpp 


编译运行即可看到结果


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值