Press "Enter" to skip to content

How to Thrift on Windows 10

About Thrift

Apache Thrift is a remote procedure call (RPC) framework. With Thrift you don’t need complicated socket programming. Contrast to ease of use on Linux and macOSs, many are having difficult times building and using Thrift on Windows 10. Most Thrift guides on the internet miss some parts. Here’s the correct way to build and use Thrift on Windows 10.

Building Thrift

Dependencies and Prerequisites

  • Boost: As you know, boost is super useful.
  • OpenSSL: for secure socket
  • libevent: for callback

Boost

  • Download Boost. At this time, 1.6.4.0 is the most recent and stable version
    • You must download a correct binary file with corresponding MSVC version and OS addressing mode (32/64 bits).
    • You can check MSVC version of a project which will use Thrift in project property pages. I downloaded boost_1_64_0-msvc-14.1-64.exe

  • Execute the downloaded file to extract Boost files

  • Open Native Tools Command Prompt and change the working directory to where Boost files are located. In my case, C:boost_1_64_0
  • Execute bootstrap first and execute the following command.

    b2 --build-type=minimal --stagedir=stage/x64 ^
      threading=multi link=static toolset=msvc-14.0 ^
      variant=release address-model=64 architecture=x86 ^
      -j8
    

    Options are:

    --stagedir: directory to store built files
    threading=multi: build thread-safe Boost
    link=static: build static Boost library
    toolset=msvc-14.0: Visual Studio MSVC (Platform Toolset) used for a project
    variant=release: Debug/Release configuration used for a project
    address-model=64: addressing mode of your OS
    architecture=x86: your CPU architecture
    

OpenSSL

  • Download OpenSSL v1.0.2L binary
    (v1.1.0 causes an SSLv3_method-related error when building Thrift, at least in my case)

    • Not light version, and be careful of the addressing mode of your OS
  • Install OpenSSL by executing the downloaded file. I installed it under C:OpenSSL-Win64

libevent

  • Download libevent-2.0.22 (v2.1.8 also has an issue)
  • Extract it under C:libevent-2.0.22-stable, whatever
  • Open Native Tools Command Prompt and build it by executing nmake -f Makefile.nmake

Main Part: Thrift

  • Download Thrift 0.9.2 (v0.9.3 and later version have an issue) and extract it to somewhere (C:thrift-0.9.2, in my case)
  • Open a solution thrift.sln under C:thrift-0.9.2libcpp. There are two projects: libthrift and libthriftnb
  • Open property pages and adjust Target Platform Version and Platform Toolset as the same as a project which you are working on
    • Set parameters as the following:
      • libthrift
        • C/C++ > General > Additional Include Directories
          • C:OpenSSL-Win64include, C:boost_1_64_0
        • Librarian > All Options
          • Additional Dependencies
            • libeay32.lib, ssleay32.lib, libeay32MT.lib, ssleay32MT.lib
          • Additional Library Directories
            • C:OpenSSL-Win64lib, C:OpenSSL-Win64libVCstatic

        Note that you need to add other library files and directories according to static/dynamic link and Debug/Release configuration

      • libthriftnb
        • C/C++ > General > Additional Include Directories
          • C:libevent-2.0.22-stableinclude, C:libevent-2.0.22-stableWIN32-Code, C:libevent-2.0.22-stable, C:boost_1_64_0
  • Build libthrift and libthriftn in order

Testing Thrift

  • Grab the example code and make a project for each server and client
  • Get the Thrift compiler and compile Thrift definition files above
  • Set parameters of each project as the following:

    • C/C++ > General > Additional Include Directories
      • C:boost_1_64_0, C:thrift-0.9.2libcppsrcthriftwindows, C:thrift-0.9.2libcppsrc
    • Linker > All Options
      • Additional Dependencies
        • libthrift.lib
      • Additional Library Directories
        • C:thrift-0.9.2libcppx64Release, C:boost_1_64_0stagex64lib

      Note that you need to add other directories according to Debug/Release configuration

  • Build and start a server project and then a client project. You can see Thrift working