1. Preparation
2. Steps
- CMD run vcvarsall.bat AMD64 set specified environment parameters
- CD Catalog: Tensorflow\contrib\cmake
- Create a build directory, CD build
CMake command
cmake .. -G "Visual Studio 15 2017 Win64" -T host=x64 -DCMAKE_BUILD_TYPE=Release ^
-Dtensorflow_VERBOSE=ON ^
-Dtensorflow_ENABLE_GRPC_SUPPORT=OFF ^
-Dtensorflow_BUILD_PYTHON_BINDINGS=OFF ^
-Dtensorflow_BUILD_CC_EXAMPLE=OFF ^
-Dtensorflow_BUILD_SHARED_LIB=ON ^
-Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX
#-DSWIG_EXECUTABLE=swig.exe的路径
#-DPYTHON_EXECUTABLE=python.exe的路径(anaconda3路径/python.exe)
#-DPYTHON_LIBRARIES=python35.lib的路径(anaconda3路径/libs/python35.lib)
The above command explains:
-g Specifies the build target version. command line input cmake-g, you can view the optional version list.
T-Host=64 is one of the many tutorials on the web that I have previously compiled with VS2017 because I did not specify-t host=64, resulting in a 32-bit compiler with fatal error C1060: "The compiler has insufficient heap space" errors.
Tensorflow_verbose compile-time output specific information, set to on a bit to reduce the compilation speed.
Tensorflow_enable_grpc_support GRPC Support, if you have a server/client business need, or cross-language GRPC usage requirements, select on.
Tensorflow_build_python_bindings needs to compile the PYTHON package, select on.
Tensorflow_build_cc_example compile the test code.
Tensorflow_build_shared_lib compile the shared library.
TENSORFLOW_WIN_CPU_SIMD_OPTIONS=/ARCH:AVX2 Select AVX or AVX2, depending on whether your CPU supports the instruction set.
Tensorflow_enable_gpu whether the GPU is used for compilation.
The Tensorflow_optimize_for_native_arch can be set to off or not, and will be automatically judged.
Other optional parameters can be viewed in the tensorflow\tensorflow\contrib\cmake\cmakelists.txt, and for the parameters you are unsure about, keep them by default.
Compile
MSBuild /p:Configuration=Release /p:Platform=x64 /verbosity:detailed tensorflow.vcxproj
这里强调一点,Configuration定义的要与cmake时DCMAKE_BUILD_TYPE定义相同
- Run Tests
TensorFlow C + + library process logging under Windows compilation