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

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

 

step1-step4参照一下网址:

https://blog.****.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”,找到后做出如下修改

 
  1. if (tensorflow_OPTIMIZE_FOR_NATIVE_ARCH)

  2. include(CheckCXXCompilerFlag)

  3. CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)

  4. if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED)

  5. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")

  6. else()

  7. CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)

  8. if(COMPILER_OPT_ARCH_AVX_SUPPORTED)

  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")

  10. endif()

  11. endif()

  12. endif()

 

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重新生成

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

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

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

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

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

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