Building Caffe on Windows with CUDA 9.0 for VS 2013, 2015 and 2017

Building Caffe on Windows 10 has been a journey (to put it lightly). Since I have a new gen gfx card (new for 2018), it does not support CUDA 8.0. So, all posts saying you need CUDA 8.0 are outdated (at least to me). With CUDA 9.0, Windows caffe does not compile.

The good news after a couple of days of trying I’ve figured out a workaround. The only boost version that supports CUDA 9.0 as of now is boost 1.65.1 and above. But, interestingly cmake breaks with boost 1.66.0. I know, welcome to the real-world versioning hell when it comes to actually building stuff.

So, if you got your windows source from: https://github.com/BVLC/caffe/tree/windows

You need to do a couple of stuff. First download and install boost 1.65.1 in some path. Let’s call this root directory my_boost_1_65_1 (typically C:\local\boost_1_65_1), and the library directory (which changes based upon which VS version you downloaded, typically C:\local\boost_1_65_1\lib64-msvc-14.0 for VS 2015). Yes, it sucks that MSVC version is 14.0 for VS 2015, but such is the life living in a Microsoft world.

I assume you have checked out the 1.0 version of windows caffe. Now, open the build_windows.cmd in the scripts directory, and modify the cmake command as follows (note the 3 lines referring to boost and boost paths):

cmake -G"!CMAKE_GENERATOR!" ^
-DBLAS=Open ^
-DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^
-DBUILD_SHARED_LIBS:BOOL=%CMAKE_BUILD_SHARED_LIBS% ^
-DBUILD_python:BOOL=%BUILD_PYTHON% ^
-DBUILD_python_layer:BOOL=%BUILD_PYTHON_LAYER% ^
-DBUILD_matlab:BOOL=%BUILD_MATLAB% ^
-DCPU_ONLY:BOOL=%CPU_ONLY% ^
-DCOPY_PREREQUISITES:BOOL=1 ^
-DINSTALL_PREREQUISITES:BOOL=1 ^
-DUSE_NCCL:BOOL=!USE_NCCL! ^
-DCUDA_ARCH_NAME:STRING=%CUDA_ARCH_NAME% ^
-DBOOST_NO_BOOST_CMAKE=TRUE ^
-DBOOST_ROOT=C:/boost_1_65_1 ^
-DBOOST_LIBRARYDIR=C:/boost_1_65_1/lib64-msvc-14.0 ^
"%~dp0\.."

I do the following edit as well, so I know that boost version is correct or it will fail. So, edit the boost version in Dependencies.cmake (located in the cmake directory):


# ---[ Boost
find_package(Boost 1.65 REQUIRED COMPONENTS system thread filesystem)
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Boost_INCLUDE_DIRS})
list(APPEND Caffe_DEFINITIONS PUBLIC -DBOOST_ALL_NO_LIB)
list(APPEND Caffe_LINKER_LIBS PUBLIC ${Boost_LIBRARIES})

And, by changing these two files, everything should be good. Now, execute scripts\build-windows.cmd and watch your build succeed.


l_prerequisites.vcxproj]
CUSTOMBUILD : warning : cannot resolve item 'api-ms-win-crt-heap-l1-1-0.dll' [D:\tools\caffe\build\tools\upgrade_solver_proto_text_install_prerequisites.vcxproj]
CUSTOMBUILD : -- warning : gp_resolved_file_type non-absolute file 'api-ms-win-crt-heap-l1-1-0.dll' returning type 'system' -- possibly incorrect [D:\tools\caffe\build\tools\upgrade_solver_proto_text_install_
prerequisites.vcxproj]
CUSTOMBUILD : warning : cannot resolve item 'api-ms-win-crt-stdio-l1-1-0.dll' [D:\tools\caffe\build\tools\upgrade_solver_proto_text_install_prerequisites.vcxproj]
CUSTOMBUILD : -- warning : gp_resolved_file_type non-absolute file 'api-ms-win-crt-stdio-l1-1-0.dll' returning type 'system' -- possibly incorrect [D:\tools\caffe\build\tools\upgrade_solver_proto_text_install
_prerequisites.vcxproj]
CUSTOMBUILD : warning : cannot resolve item 'api-ms-win-crt-convert-l1-1-0.dll' [D:\tools\caffe\build\tools\upgrade_solver_proto_text_install_prerequisites.vcxproj]
CUSTOMBUILD : -- warning : gp_resolved_file_type non-absolute file 'api-ms-win-crt-convert-l1-1-0.dll' returning type 'system' -- possibly incorrect [D:\tools\caffe\build\tools\upgrade_solver_proto_text_insta
ll_prerequisites.vcxproj]

6897 Warning(s)
0 Error(s)

Time Elapsed 00:14:44.49

Let me know in the comments if you run into more issues.

17 thoughts on “Building Caffe on Windows with CUDA 9.0 for VS 2013, 2015 and 2017

  1. Hi Tharindu,

    Thanks a lot for your instructions.

    I followed your steps exactly, however when running ./srcripts/build_win.cmd, I got error messages below.
    Would you please give me a hint? Thank you very much.

    I can see boost_python3-vc140-mt-gd-1_65_1.dll/lib, as well as boost_python3-vc140-mt-1_65_1.dll/lib in $BOOST_LIBRARYDIR

    Do not know why it is complaining that python interface is disabled?

    The system cannot find the drive specified.
    The system cannot find the drive specified.
    INFO: ============================================================
    INFO: Summary:
    INFO: ============================================================
    INFO: MSVC_VERSION = 14
    INFO: WITH_NINJA = 1
    INFO: CMAKE_GENERATOR = “Ninja”
    INFO: CPU_ONLY = 0
    INFO: CUDA_ARCH_NAME = Auto
    INFO: CMAKE_CONFIG = Release
    INFO: USE_NCCL = 0
    INFO: CMAKE_BUILD_SHARED_LIBS = 0
    INFO: PYTHON_VERSION = 2
    INFO: BUILD_PYTHON = 1
    INFO: BUILD_PYTHON_LAYER = 1
    INFO: BUILD_MATLAB = 0
    INFO: PYTHON_EXE = “python”
    INFO: RUN_TESTS = 0
    INFO: RUN_LINT = 0
    INFO: RUN_INSTALL = 0
    INFO: ============================================================
    CMake Warning (dev) at cmake/Dependencies.cmake:11 (find_package):
    Policy CMP0074 is not set: find_package uses PackageName_ROOT variables.
    Run “cmake –help-policy CMP0074” for policy details. Use the cmake_policy
    command to set the policy and suppress this warning.

    Environment variable Boost_ROOT is set to:

    C:\Users\twang\Downloads\boost_1_65_1\boost_1_65_1\

    For compatibility, CMake is ignoring the variable.
    Call Stack (most recent call first):
    CMakeLists.txt:80 (include)
    This warning is for project developers. Use -Wno-dev to suppress it.

    — Boost version: 1.65.1
    — Found the following Boost libraries:
    — system
    — thread
    — filesystem
    — chrono
    — date_time
    — atomic
    — Found gflags (include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: gflags_shared)
    — Found glog (include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: glog)
    — Found PROTOBUF Compiler: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/bin/protoc.exe
    — Found lmdb (include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: lmdb)
    — Found LevelDB (include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: leveldb)
    — Found Snappy (include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: snappy_static;optimized;C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/caffezlib.lib;debug;C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/caffezlibd.lib)
    — CUDA detected: 9.0
    — Found cuDNN: ver. 7.1.4 found (include: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/include, library: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/lib/x64/cudnn.lib)
    — Added CUDA NVCC flags for: sm_61
    — OpenCV found (C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries)
    — Found OpenBLAS libraries: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/libopenblas.dll.a
    — Found OpenBLAS include: C:/Users/twang/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include
    — NumPy ver. 1.15.0 found (include: C:/Users/twang/AppData/Local/Programs/Python/Python35/lib/site-packages/numpy/core/include)
    — Could NOT find Boost
    — Python interface is disabled or not all required dependencies found. Building without it…

    — ******************* Caffe Configuration Summary *******************
    — General:
    — Version : 1.0.0
    — Git : 1.0-111-g509dae05-dirty
    — System : Windows
    — C++ compiler : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
    — Release CXX flags : /MD /O2 /Ob2 /DNDEBUG /FS /DWIN32 /D_WINDOWS /W3 /GR /EHsc /FS
    — Debug CXX flags : /MDd /Zi /Ob0 /Od /RTC1 /FS /DWIN32 /D_WINDOWS /W3 /GR /EHsc /FS
    — Build type : Release

    — BUILD_SHARED_LIBS : 0
    — BUILD_python : 1
    — BUILD_matlab : 0
    — BUILD_docs :
    — CPU_ONLY : 0
    — USE_OPENCV : ON
    — USE_LEVELDB : ON
    — USE_LMDB : ON
    — USE_NCCL : 0
    — ALLOW_LMDB_NOLOCK : OFF

    — Dependencies:
    — BLAS : Yes (Open)
    — Boost : Yes (ver. 1.65)
    — glog : Yes
    — gflags : Yes
    — protobuf : Yes (ver. 3.1.0)
    — lmdb : Yes (ver. 0.9.70)
    — LevelDB : Yes (ver. 1.18)
    — Snappy : Yes (ver. 1.1.1)
    — OpenCV : Yes (ver. 3.1.0)
    — CUDA : Yes (ver. 9.0)

    — NVIDIA CUDA:
    — Target GPU(s) : Auto
    — GPU arch(s) : sm_61
    — cuDNN : Yes (ver. 7.1.4)

    — Install:
    — Install path : C:/Users/twang/src/caffe/build/install

    — Configuring done
    CMake Error at CMakeLists.txt:143 (add_dependencies):
    The dependency target “pycaffe” of target “pytest” does not exist.

    — Generating done
    — Build files have been written to: C:/Users/twang/src/caffe/build
    ERROR: Configure failed

  2. Hello, are you installing the cpu version? you don·t :: Add -DCUDNN_ROOT=C:/Projects/caffe/cudnn-8.0-windows10-x64-v5.1/cuda ^

      1. i got error
        “E:\Caffe\caffe-windows\build\ALL_BUILD.vcxproj”(默认目标) (1) ->
        “E:\Caffe\caffe-windows\build\src\caffe\caffe.vcxproj”(默认目标) (3) ->
        (CustomBuild 目标) ->
        C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: “cmd.exe” 已退
        出,代码为 1。 [E:\Caffe\caffe-windows\build\src\caffe\caffe.vcxproj]

        139 个警告
        1 个错误

    1. hello,have you solved this problem?i have met the same issue as you met!may you can tell me how you solved it?
      thx a lot

    2. No, I keep the paths as I’ve mentioned, cause cmake expects the libs to be in those specific libraries. But, with new cmake versions this is probably fixed, and you should be able to simply build it with a new boost library. I found out that there’s a version dependency between boost and cmake and for some weird reasons, for a new version of boost you have to upgrade to the cmake version that supports it. Then everything simply works.

  3. i followed your steps, everything was fine but at last step i got 2 link errors!

    “E:\Git_Projects\caffe\scripts\build\ALL_BUILD.vcxproj” (default target) (1) ->
    “E:\Git_Projects\caffe\scripts\build\python\pycaffe.vcxproj” (default target) (27) ->
    (Link target) ->
    _caffe.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) struct _object * __cdecl boost::python::detail::init_module(struct PyModuleDef &,void (__cdecl*)
    (void))” (__imp_?init_module@detail@python@boost@@YAPEAU_object@@AEAUPyModuleDef@@P6AXXZ@Z) referenced in function PyInit__caffe [E:\Git_Projects\caffe\scripts\build\python\pyc
    affe.vcxproj]
    E:\Git_Projects\caffe\scripts\build\lib\Release\_caffe.pyd : fatal error LNK1120: 1 unresolved externals [E:\Git_Projects\caffe\scripts\build\python\pycaffe.vcxproj]

    252 Warning(s)
    2 Error(s)

    Below is my configuration:
    E:\Git_Projects\caffe\scripts>build_win.cmd
    The system cannot find the drive specified.
    The system cannot find the drive specified.
    INFO: ============================================================
    INFO: Summary:
    INFO: ============================================================
    INFO: MSVC_VERSION = 14
    INFO: WITH_NINJA = 0
    INFO: CMAKE_GENERATOR = “Visual Studio 14 2015 Win64”
    INFO: CPU_ONLY = 0
    INFO: CUDA_ARCH_NAME = Auto
    INFO: CMAKE_CONFIG = Release
    INFO: USE_NCCL = 0
    INFO: CMAKE_BUILD_SHARED_LIBS = 0
    INFO: PYTHON_VERSION = 3
    INFO: BUILD_PYTHON = 1
    INFO: BUILD_PYTHON_LAYER = 1
    INFO: BUILD_MATLAB = 0
    INFO: PYTHON_EXE = “python”
    INFO: RUN_TESTS = 0
    INFO: RUN_LINT = 0
    INFO: RUN_INSTALL = 0
    INFO: ============================================================
    — Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
    — Boost version: 1.65.1
    — Found the following Boost libraries:
    — system
    — thread
    — filesystem
    — chrono
    — date_time
    — atomic
    — Found gflags (include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: gflags_shared)
    — Found glog (include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: glog)
    — Found PROTOBUF Compiler: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/bin/protoc.exe
    — Found lmdb (include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: lmdb)
    — Found LevelDB (include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: leveldb)
    — Found Snappy (include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: snappy_static;optimized;C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/caffezlib.lib;debug;C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/caffezlibd.lib)
    — CUDA detected: 9.0
    — Found cuDNN: ver. 7.0.5 found (include: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/include, library: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/lib/x64/cudnn.lib)
    — Added CUDA NVCC flags for: sm_61
    — OpenCV found (C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries)
    — Found OpenBLAS libraries: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/lib/libopenblas.dll.a
    — Found OpenBLAS include: C:/Users/user/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include
    — NumPy ver. 1.15.4 found (include: C:/Users/user/AppData/Local/Programs/Python/Python35/lib/site-packages/numpy/core/include)
    — Boost version: 1.65.1
    — Found the following Boost libraries:
    — python

    — ******************* Caffe Configuration Summary *******************
    — General:
    — Version : 1.0.0
    — Git : 1.0-111-g509dae05-dirty
    — System : Windows
    — C++ compiler : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
    — Release CXX flags : /MD /O2 /Ob2 /DNDEBUG /DWIN32 /D_WINDOWS /W3 /GR /EHsc
    — Debug CXX flags : /MDd /Zi /Ob0 /Od /RTC1 /DWIN32 /D_WINDOWS /W3 /GR /EHsc
    — Build type : Release

    — BUILD_SHARED_LIBS : 0
    — BUILD_python : 1
    — BUILD_matlab : 0
    — BUILD_docs :
    — CPU_ONLY : 0
    — USE_OPENCV : ON
    — USE_LEVELDB : ON
    — USE_LMDB : ON
    — USE_NCCL : 0
    — ALLOW_LMDB_NOLOCK : OFF

    — Dependencies:
    — BLAS : Yes (Open)
    — Boost : Yes (ver. 1.65)
    — glog : Yes
    — gflags : Yes
    — protobuf : Yes (ver. 3.1.0)
    — lmdb : Yes (ver. 0.9.70)
    — LevelDB : Yes (ver. 1.18)
    — Snappy : Yes (ver. 1.1.1)
    — OpenCV : Yes (ver. 3.1.0)
    — CUDA : Yes (ver. 9.0)

    — NVIDIA CUDA:
    — Target GPU(s) : Auto
    — GPU arch(s) : sm_61
    — cuDNN : Yes (ver. 7.0.5)

    — Python:
    — Interpreter : C:/Users/user/AppData/Local/Programs/Python/Python35/python.exe (ver. 3.5)
    — Libraries : C:/Users/user/AppData/Local/Programs/Python/Python35/libs/python35.lib (ver 3.5.0)
    — NumPy : C:/Users/user/AppData/Local/Programs/Python/Python35/lib/site-packages/numpy/core/include (ver 1.15.4)

    — Install:
    — Install path : E:/Git_Projects/caffe/scripts/build/install

    — Configuring done

      1. Thanks for your reply. I’m using “boost_1_65_1-msvc-14.0-64.exe” 64bit boost on 64bit windows 10

  4. i have included configuration details in above message…
    ” C++ compiler : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe”

    i have visual studio 2015 installed.. it looks like i am using 64bit compiler by above line..
    is there something else that i’m missing ?

  5. What about warning? Is it makes problem after installation? How can we remove warning?

Leave a reply to Tracy Cancel reply