您的位置:首页 > 其它

windows下使用thrift编译+示例+详解解决坑

2017-07-04 12:50 555 查看
Thrift 在windows下使用略坑!
win7sp1 环境
Thrift依赖环境很多,具体如下:

1.   libevent-2.0.21-stable.tar.gz

2.   openssl-OpenSSL_1_1_0d

3.   git-thirft-0.9.3

4.   boost_1_59_0.zip

5.   vs2010

6.   vs2010SP1

7.   windows SDK 7.1               GRMSDKX_EN_DVD.iso

首先 坚决!!!不要使用 github上面 https://github.com/apache/thrift 直接下载的 thrift-0.9.3.tar.gz

        推荐 使用git上,切换到指定tags下,指定版本,通过 git clone https://github.com/apache/thrift.git

        下载源码方式编译,下载的源码跟下载的thrift-0.9.3.tar.gz内部不太一致,不过下载的源码也需要稍作修改,直接编译是无法编译通过

编译测试程序:

       VS2010-SP1 测试程序 使用 /Mtd 编译

       需要注意:指定头文件目录+lib目录

#include <transport/TSocket.h>

#include <transport/TBufferTransports.h>  

#include <protocol/TBinaryProtocol.h>

#include "./gen-cpp/APService.h"

#include "./gen-cpp/ap_types.h"

#include "./gen-cpp/aphead_types.h"

#include <boost/system/error_code.hpp>

#pragma comment(lib, "crypt32.lib")

#pragma comment(lib, "User32.lib")

#pragma comment(lib, "libssl.lib")

#pragma comment(lib, "libcrypto.lib")

#pragma comment(lib, "libthrift.lib")

using namespace apache::thrift;

using namespace apache::thrift::protocol; 

using namespace apache::thrift::transport;

using namespace com::vrv::im;

using namespace std;

编译boost:

.\b2 --build-type=complete toolset=msvc-10.0 threading=multi link=static address-model=32 install

编译thrift:

       VS2010-SP1 Thrift   使用 /Mtd 编译

编译openssl:

openssl             使用纯静态编译lib,保证openssl\bin目录下没有ssl.dll crypto.dll

perl ./Configure VC-WIN32 no-shared no-asm --prefix=c:\openssl

nmake

nmake install

参考资料:

1、下载 openssl-1.1.0.tar.gz

2、安装 ActivePerl, 可以到http://www.activestate.com/activeperl/downloads下载最新版本, 需要用到 perl 解释器。

     注:Perl 最低版本要求5.10以上,Windows XP用户最后支持版本ActivePerl 5.20.2.2002 版本

3、使用 VS2010 下的 Visual Studio 2010 Command Prompt 进入控制台模式 (这个模式会自动设置各种环境变量,根据编译32位、64位、Itanium自己选择)。

4、安装dmake,ppm install dmake

5、解压缩 openssl 源代码包,进入 openssl 的根目录, 如 E:\openssl-1.1.0。

6、perl configure VC-WIN32

必须在 c:\openssl-1.1.0 目录下执行该命令, 否则找不到 Configure 文件, 这时就必须指定完整的 Configure 文件路径。

64编译的话 Win64/x64 执行 perl Configure VC-WIN64A;Win64/IA64 执行 perl Configure VC-WIN64I。

7、在正式编译之前

(1). 找到 c:\openssl-1.1.0\configdata.pm和c:\openssl-1.1.0\makefile两个文件, 用记事本打开, 搜索 “/MD” 字符串, 替换成 “/MT”, 这将导致静态链接 C 运行, 避免了在目标机器上安装 VC 再发行包等等操作。

8、编译, nmake

9、编译, nmake test

10、编译, nmake install

      注:openssl 1.1.0开始由原先的libeay32.dll、ssleay32.dll变成了libcrypto-1_1.dll、libssl-1_1.dll,一些加密方式也发生了变化。

参考资料:

   写的很好

    Apache Thrift 在Windows下的安装与开发

    http://blog.csdn.net/colouroo/article/details/38588297
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: