本文主要介紹怎么在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
