Tuesday, February 4, 2020

Build Caffe for VS 2017 (1)

During my project in LightVision Inc., I had to build a Caffe deep learning framework with following conditions.
  1. Windows 10
  2. Visual Studio 2017 (VS 2017)
  3. Specific versions of dependent libraries (e.g., OpenCV 4.1 and latest Boost library)
This article contains my struggles to tackle the mission.

To build the Caffe from scratch in Windows, you would better start from this repo (Caffe-Builder).

In this repo, the authors provide automated ways of building required libraries for the Caffe in Windows.

The list of the libraries in Caffe-Builder are as follows.
  • Boost
  • gflags
  • glog
  • HDF5
  • LevelDB
  • LMDB
  • OpenBLAS
  • protobuf
  • snappy
  • zlib
If you are using VS 2013 or 2015, you may not need any modification for this project.

However, to build Caffe with VS 2017, some modifications for CMake files are necessary.

Before proceeding further, you need to get following prerequisites:
  1. Latest version of CMake
  2. VS 2017
  3. Git
As opposed to the readme file in Caffe-Builder repo, Ninja is not a necessary component.

After getting prerequisites and cloning the repo, update following CMake file related to Boost.

%caffe-builder-root%/packages/boost/CMakeLists.txt


3     -project(boost VERSION 1.61.0)
3     +project(boost VERSION 1.69.0)

47    -URL https://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.7z
47    +URL https://sourceforge.net/projects/boost/files/boost/1.69.0/boost_1_69_0.7z

81    +set(MSVC_VERSION_MAP_1916 msvc-14.1)


Those changes make Boost and CMake recognize VS 2017 version 15.9.

To get the internal version numbering information of VS, please refer this article in Wikipedia.

Then, configure and generate the project using CMake with following options:


I configured these options based on the "build_v140_x64.cmd" file in the repo.

Key differences between my options and options in "build_v140_x64.cmd" are as follows:  
  • Build Boost libraries with static link
  • Do not build OpenCV

After finishing the project generation, you can get all relevant libraries by building ALL_BUILD project in the solution.

In the next article, we will build the Caffe framework by using the libraries just built by us.