This is a prebuilt TensorFlow library for Windows. Both static and dynamic libraries are pre-built, which can be used to link to your existing Visual Studio projects.
Three simple steps to build a standalone TensorFlow C++ program:
- Git clone this project. Git LFS is used to hold large files.
- Install Visual Studio 2017 Preview 2.1
- Open this example Visual Studio solution. Build, and go!
OS: Windows 10 Compiler: Visual Studio 2017 Preview 2.1
Note that: You can skip this by just cloning my prebuilt library. It's much easier
Open a Visual Studio 2017 command prompt (you can find it in start menu)
cd tensorflow/contrib/cmake
mkdir build
cd build
cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
-DSWIG_EXECUTABLE=c:\swigwin-3.0.12\swig.exe ^
-DPYTHON_EXECUTABLE=C:\Users\Peter\AppData\Local\Programs\Python\Python36\python.exe ^
-DPYTHON_LIBRARIES=C:\Users\Peter\AppData\Local\Programs\Python\Python36\libs\python36.lib
If you're using Visual Studio 2017, seems that it needs to invoke x64 compiler:
- Open 'tf_core_kernels' project.
- Open the property of the project.
- Choose configuration to 'All Configurations'
- Choose platform to 'x64 (Active)'
- Modify
$(VC_ExecutablePath_x64)
to$(VC_ExecutablePath_x64_x64)
Then, invoke the builder.
MSBuild /p:Configuration=Release ALL_BUILD.vcxproj
This will cost more than one hour, and eat more than 8GB memory. Also make sure you're connected to internet before leaving for a cup of coffee.
Just execute the collect script to collect them into include
and lib
folders.
To figure out what's the actual dependencies, one can take a look of the the project tf_tutorials_example_trainer
, you can find the linker dependencies in the <AdditionalDependencies>
tag:
Release\tf_protos_cc.lib
zlib\install\lib\zlibstatic.lib
gif\install\lib\giflib.lib
png\install\lib\libpng12_static.lib
jpeg\install\lib\libjpeg.lib
lmdb\install\lib\lmdb.lib
jsoncpp\src\jsoncpp\src\lib_json\$(Configuration)\jsoncpp.lib
farmhash\install\lib\farmhash.lib
fft2d\\src\lib\fft2d.lib
highwayhash\install\lib\highwayhash.lib
nsync\install\lib\nsync.lib
protobuf\src\protobuf\$(Configuration)\libprotobuf.lib
re2\src\re2\$(Configuration)\re2.lib
sqlite\install\lib\sqlite.lib
grpc\src\grpc\Release\grpc++_unsecure.lib
grpc\src\grpc\Release\grpc_unsecure.lib
grpc\src\grpc\Release\gpr.lib
snappy\src\snappy\$(Configuration)\snappy.lib
Furthermore, there are object file dependencies described in the cmake file. They're all resolved and collected into the collect script
Tensorflow has this trainer example to demonstrate the use of C++ API. That demo code is copied under the example, and a working Visual Studio project is located under the example folder.
Just open the Visual Studio project, and you are good to go!