You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler
You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler
// matmul.h
#pragma once
#define COMPILER_MSVC
#define NOMINMAX
https://www.jianshu.com/p/052c0a669337
从上一篇的Tensorflow win10 c++ 运行 python训练出的模型,按照Tensorflow官网给出的cmake构建和编译方案,我们实际编译了tensorflow的c++库,能够运行官方的example。那么新建一个单独的工程需要进行一定的配置。
源代码使用官方的源码main.cc
这份代码包含了读取模型,读取图片数据,进行模型预测等,足够满足简单的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的相应位置。
至此,程序就可以编译调试了。
作者:菜鸟游侠k2
链接:https://www.jianshu.com/p/052c0a669337
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/80397199
- 点赞
- 收藏
- 关注作者
评论(0)