在windows平台cmake编译tensorflow ( cmake + win10 + visualstudio2017 )

step1-step4参照一下网址:

https://blog.csdn.net/dageda1991/article/details/79721333

后面主要记录一下编译过程中遇到的问题如何解决的

step1:打开

step2:下载依赖的软件

        visual studio 2017,  swig, python3.5以上,cmake,git

step3:下载源码

        https://github.com/tensorflow/tensorflow.git

configure之前需修改如下两个地方

1>下载好tensorflow源码后,找到tensorflow/contrib/cmake/CMakeLists.txt,搜索“tensorflow_OPTIMIZE_FOR_NATIVE_ARCH”,找到后做出如下修改

if (tensorflow_OPTIMIZE_FOR_NATIVE_ARCH)
  include(CheckCXXCompilerFlag)
  CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
  if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
  else()
    CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)
    if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
    endif()
  endif()
endif()

2>找到tensorflow\contrib\cmake\external\protobuf.cmake,修改protobuf的版本,将3.6.0修改成3.6.1

step4:cmake  工程配置:

          右键-更多-以管理员身份运行,先cd到tensorflow/contrib/cmake/build目录下,再输入以下内容进行configure

D:/ProgramFiles/cmake/cmake-3.11.4-win64-x64/bin/cmake .. -A x64 -DCMAKE_BUILD_TYPE=Debug -DSWIG_EXECUTABLE=D:/ProgramFiles/swigwin-3.0.12/swig.exe -DPYTHON_EXECUTABLE=D:/ProgramFiles/Python/Python3.5/python.exe -DPYTHON_LIBRARIES=D:/ProgramFiles/Python/Python3.5/libs/python35.lib -Dtensorflow_ENABLE_GPU=OFF -Dtensorflow_ENABLE_GRPC_SUPPORT=ON -Dtensorflow_BUILD_SHARED_LIB=ON

step5:编译

        在tensorflow/contrib/cmake/build下打开工程文件tensorflow.sln,然后选择ALL_BUILD重新生成

编译过程中可能以下问题:

解决方法:参照的这篇帖子

https://github.com/tensorflow/tensorflow/issues/19722

在windows平台cmake编译tensorflow ( cmake + win10 + visualstudio2017 )_第1张图片

如果编译工程中还有此问题出现,单独设置工程的c/c++包含路径,让它能找到qrpcpp/grpcpp.h即可

        

       

 

你可能感兴趣的:(tensorflow)