Building Thrift on Windows 10

Contrast to 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.

Dependencies

  • Boost
  • OpenSSL (for secure socket)
  • libevent (for callback)

Boost

  • Download boost. At this time of writing, the latest version is 1.64.0. I downloaded boost_1_64_0-msvc-14.1-64.exe.
    • You must download a correct binary with consideration of OS addressing mode (32/64 bits) and MSVC version
    • You can check MSVC version in a project property page of a project which will use Thrift
  • Execute the downloaded file to extract files. In my case, C:\boost_1_64_0

  • Open **Native Tools Command Prompt** and execute the following commands

    1
    2
    3
    4
    5
    6
    cd C:\boost_1_64_0
    bootstrap
    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 (not light version)
    • v1.1.0 causes an SSLv3_method-related error when building Thrift, at least in my case
    • 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 has an issue)
  • Extract it under C\:libevent-2.0.22-stable, or whereever you want
  • Open **Native Tools Command Prompt** and build it by executing nmake -f Makefile.nmake

Building 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.2\lib\cpp. 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-Win64\include, C:\boost_1_64_0
      • Librarian > All Options
        • Additional Dependencies
          • libeay32.lib, ssleay32.lib, libeay32MT.lib, ssleay32MT.lib
        • Additional Library Directories
          • C:\OpenSSL-Win64\lib, C:\OpenSSL-Win64\lib\VC\static

      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-stable\include, C:\libevent-2.0.22-stable\WIN32-Code, C:\libevent-2.0.22-stable, C:\boost_1_64_0
  • Build libthrift and libthriftn sequentially

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.2\lib\cpp\src\thrift\windows, C:\thrift-0.9.2\lib\cpp\src
    • Linker > All Options
      • Additional Dependencies
        • libthrift.lib
      • Additional Library Directories
        • C\:thrift-0.9.2\lib\cpp\x64\Release, C:\boost_1_64_0\stage\x64\lib

          Note: you may 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