You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler

举报
风吹稻花香 发表于 2021/06/04 23:18:13 2021/06/04
【摘要】 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 ...


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功能需求。
注意的是,需要在代码头部加上


    
  1. #define COMPILER_MSVC
  2. #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到自己的工程文件


    
  1. D:\Projects\tensorflow
  2. D:\Projects\tensorflow\tensorflow\contrib\cmake\build
  3. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\zlib_archive
  4. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\gif_archive\giflib-5.1.4
  5. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\png_archive
  6. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\jpeg_archive
  7. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\eigen_archive
  8. D:\Projects\tensorflow\third_party\eigen3
  9. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\gemmlowp\src\gemmlowp
  10. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\jsoncpp\src\jsoncpp
  11. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\farmhash_archive
  12. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\farmhash_archive\util
  13. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\external\highwayhash
  14. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\protobuf\src\protobuf\src
  15. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\grpc\src\grpc\include
链接设置

按照tf_label_image_example.vcxproj添加依赖项目,按照博客添加额外依赖路径


    
  1. kernel32.lib
  2. user32.lib
  3. gdi32.lib
  4. winspool.lib
  5. shell32.lib
  6. ole32.lib
  7. oleaut32.lib
  8. uuid.lib
  9. comdlg32.lib
  10. advapi32.lib
  11. Release\tf_protos_cc.lib
  12. zlib\install\lib\zlibstatic.lib
  13. gif\install\lib\giflib.lib
  14. png\install\lib\libpng12_static.lib
  15. jpeg\install\lib\libjpeg.lib
  16. jsoncpp\src\jsoncpp\src\lib_json\$(Configuration)\jsoncpp.lib
  17. farmhash\install\lib\farmhash.lib
  18. fft2d\\src\lib\fft2d.lib
  19. highwayhash\install\lib\highwayhash.lib
  20. protobuf\src\protobuf\$(Configuration)\libprotobuf.lib
  21. grpc\src\grpc\$(Configuration)\grpc++_unsecure.lib
  22. grpc\src\grpc\$(Configuration)\grpc_unsecure.lib
  23. grpc\src\grpc\$(Configuration)\gpr.lib
  24. wsock32.lib
  25. ws2_32.lib
  26. shlwapi.lib

    
  1. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\protobuf\src\protobuf\Release
  2. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc.dir\Release
  3. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc_ops.dir\Release
  4. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_cc_framework.dir\Release
  5. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_cpu.dir\Release
  6. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_direct_session.dir\Release
  7. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_framework.dir\Release
  8. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.dir\Release
  9. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.dir\Release
  10. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\tf_core_ops.dir\Release
  11. D:\Projects\tensorflow\tensorflow\contrib\cmake\build\Release
  12. 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

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。