本文主要介绍怎么在windows+VisualStudio 2013 下编译 thrift compiler, 在thrift官网有教程: http://thrift.apache.org/docs/BuildingFromSource, 不过里面有些地方过时了,提供的flex和bison工具下载链接也已失效, 所以本文在原教程基础上做了一些整理。
第一步: 使用git 下载 thrift源码
git clone https://git-wip-us.apache.org/repos/asf/thrift.git thrift
第二步:编译
- 下载 unixutil, 我们需要里面包含的flex.exe和bison.exe:http://unxutils.sourceforge.net/
- 解压 unixutil.zip到 目录A
- 将目录A添加到Windows环境变量Path中去, 注意是添加不是替换.
- 设置bison.simple
- 下载bison.simple, 放到目录B中
- 定义Windows环境变量 BISON_SIMPLE = 目录B\bison.simple
- 下载inttypes.h, 放到 thrift\compiler\cpp\src\
- 生成源码
- 命令行下转到 thrift\compiler\cpp\ 下, 执行如下命令行:
flex -osrc\thriftl.cc src\thriftl.ll
在生成的thriftl.cc中 注释掉 #include <unistd.h>
- 继续执行:
bison -y -o “src/thrifty.cc” –defines src/thrifty.yy move src\thrifty.cc.hh src\thrifty.hh move src\windows\version.h.in src\windows\version.h
- 命令行下转到 thrift\compiler\cpp\ 下, 执行如下命令行:
5. 使用VS2013, 打开thrift\compiler\cpp\compiler.sln
6. 在项目属性中, 去掉BuildEvent中的内容
7. 编译项目, 一切顺利的话, 应该能够得到thrift.exe文件
注: thrift 编译有两个文件(bison.simple 和 inttypes.h), 比较难找到,在此下载: http://pan.baidu.com/s/1jGmmKqq