從上一篇的Tensorflow win10 c++ 運行 python訓練出的模型窒盐,按照Tensorflow官網(wǎng)給出的cmake構建和編譯方案钢拧,我們實際編譯了tensorflow的c++庫,能夠運行官方的example葡粒。那么新建一個單獨的工程需要進行一定的配置膜钓。
源代碼使用官方的源碼main.cc
這份代碼包含了讀取模型,讀取圖片數(shù)據(jù)夫壁,進行模型預測等沃疮,足夠滿足簡單的tensorflow功能需求司蔬。
注意的是,需要在代碼頭部加上
#define COMPILER_MSVC
#define NOMINMAX
原因如這篇博客所述
If you omit the COMPILER_MSVC definition, you will run into an error saying “You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler.” If you omit the NOMINMAX definition, you will run into a number of errors saying “’(‘: illegal token on right side of ‘::’”. (The reason for this is that <Windows.h> gets included somewhere, and Windows has macros that redefine min and max. These macros are disabled with NOMINMAX.)
工程屬性設置
接下來配置文件肺缕,首先本文同步的tensorflow源代碼位置為D:\Projects\tensorflow。
附加包含路徑
設置對應如下的包含路徑炒辉,可以通過直接編輯官方例子tf_label_image_example.vcxproj到自己的工程文件
D:\Projects\tensorflow
D:\Projects\tensorflow\tensorflow\contrib\cmake\build
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\zlib_archive
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\gif_archive\giflib-5.1.4
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\png_archive
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\jpeg_archive
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\eigen_archive
D:\Projects\tensorflow\third_party\eigen3
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\gemmlowp\src\gemmlowp
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\jsoncpp\src\jsoncpp
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\farmhash_archive
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\farmhash_archive\util
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\highwayhash
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\protobuf\src\protobuf\src
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\grpc\src\grpc\include
鏈接設置
按照tf_label_image_example.vcxproj添加依賴項目黔寇,按照博客添加額外依賴路徑
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
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
jsoncpp\src\jsoncpp\src\lib_json\$(Configuration)\jsoncpp.lib
farmhash\install\lib\farmhash.lib
fft2d\\src\lib\fft2d.lib
highwayhash\install\lib\highwayhash.lib
protobuf\src\protobuf\$(Configuration)\libprotobuf.lib
grpc\src\grpc\$(Configuration)\grpc++_unsecure.lib
grpc\src\grpc\$(Configuration)\grpc_unsecure.lib
grpc\src\grpc\$(Configuration)\gpr.lib
wsock32.lib
ws2_32.lib
shlwapi.lib
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\protobuf\src\protobuf\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc_ops.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc_framework.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_cpu.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_direct_session.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_framework.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_ops.dir\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build\Release
D:\Projects\tensorflow\tensorflow\contrib\cmake\build
添加預編譯好的obj文件缝裤,在tf_label_image_example.vcxproj文件中找到
<Object Include="D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.dir\$(Configuration)\arena.obj" />
開頭的一長串語句憋飞,復制到我們工程目錄中vcxproj的相應位置姆吭。
至此,程序就可以編譯調試了检眯。