使用 Cmake 和 Ninja 编译 Caffe 失败

Compiling Caffe with Cmake and Ninja fails

我尝试在启用 CMAKE_BUILD_SHARED_LIBS 选项的情况下在 windows 上编译 Caffe,但它失败了,并表示我需要使用 Ninja。当我在配置文件 (build_win.cmd) 和 运行 脚本中将 Ninja 设置为 1 时,它会抱怨并给出以下错误消息:

 CMake Error: CMake was unable to find a build program corresponding to
 "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select
 a different build tool. CMake Error: CMAKE_C_COMPILER not set, after
 EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after
 EnableLanguage
 -- Configuring incomplete, errors occurred! ERROR: Configure failed

我不知道我还需要采取哪些其他步骤才能成功完成编译过程。我所做的就是下载 Ninja,将其解压到某处并将其添加到我的环境变量中。

我还需要安装 gcc 吗?

更新

正如评论中所建议的那样,我检查了我的路径,发现它配置错误。我修复了现在出现这些错误,似乎找不到所需的库:

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/Users/Master/gcc/bin/gcc.exe
-- Check for working C compiler: C:/Users/Master/gcc/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Users/Master/gcc/bin/c++.exe
-- Check for working CXX compiler: C:/Users/Master/gcc/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  cmake/Dependencies.cmake:8 (find_package)
  CMakeLists.txt:79 (include)


CMake Warning at C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  cmake/Dependencies.cmake:8 (find_package)
  CMakeLists.txt:79 (include)


CMake Warning at C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  cmake/Dependencies.cmake:8 (find_package)
  CMakeLists.txt:79 (include)


-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:1793 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  cmake/Dependencies.cmake:8 (find_package)
  CMakeLists.txt:79 (include)


-- Could NOT find GFlags (missing:  GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
-- Could NOT find Glog (missing:  GLOG_INCLUDE_DIR GLOG_LIBRARY)
CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
  Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindProtobuf.cmake:393 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/ProtoBuf.cmake:9 (find_package)
  cmake/Dependencies.cmake:48 (include)
  CMakeLists.txt:79 (include)


-- Configuring incomplete, errors occurred!
See also "G:/caffe_latest2/build/CMakeFiles/CMakeOutput.log".
See also "G:/caffe_latest2/build/CMakeFiles/CMakeError.log".
ERROR: Configure failed

我找到了原因。我在我的系统上安装了 GCC,cmake 会尝试使用它而不是 Visual C++ 编译器。
所需要的只是下载 Ninja,将它放在你的路径变量中,你就可以开始了。
build_win.cmd 中更改所需的设置以使用 Ninja,您就完成了