1. 程式人生 > >Ubuntu 16.04中用bazel交叉編譯tensorflow lite

Ubuntu 16.04中用bazel交叉編譯tensorflow lite

首先在csdn上著了大神關於這個的實踐如下連結

https://www.cnblogs.com/jojodru/p/7744630.html

但是報錯如下,說是找不到opt選項。

INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file
INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file
INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file
INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file
INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file
INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt
ERROR: Config value opt is not defined in any .rc file

INFO: Reading rc options for 'build' from /home/allen/project/tensorflow180711/tools/bazel.rc:
  'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --define=grpc_no_ares=true --spawn_strategy=standalone --genrule_strategy=standalone -c opt

ERROR: Config value opt is not defined in any .rc file

由於對bazel不熟悉所以著了一篇介紹bazel的文章

https://blog.csdn.net/elaine_bao/article/details/78668657

此文介紹了bazel的基本工作原理,比較有用的一個命令是

bazelquery--nohost_deps--noimplicit_deps'deps(//main:hello-world)'\

--outputgraph

這個命令可以用來看編譯的檔案依賴圖。

在編譯lite的時候會編譯python,這時候會導致一些錯誤如下:

/home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -nostdinc '-mfloat-abi=hard' '-mfpu=neon-vfpv4' -funsafe-math-optimizations -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/include -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/usr/include -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/usr/include -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.9.3/include -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3 -isystem /home/allen/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/arm-linux-gnueabihf -U_FORTIFY_SOURCE -fstack-protector -fPIE '-fdiagnostics-color=always' -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O3 -DNDEBUG -ffunction-sections -fdata-sections -MD -MF bazel-out/armv6-opt/bin/external/gif_archive/_objs/gif/external/gif_archive/lib/gifalloc.pic.d -fPIC -iquote external/gif_archive -iquote bazel-out/armv6-opt/genfiles/external/gif_archive -iquote external/bazel_tools -iquote bazel-out/armv6-opt/genfiles/external/bazel_tools -isystem external/gif_archive/lib -isystem bazel-out/armv6-opt/genfiles/external/gif_archive/lib -isystem bazel-out/armv6-opt/bin/external/gif_archive/lib -fPIC '-march=armv6' '-mfloat-abi=hard' '-mfpu=neon-vfpv4' -funsafe-math-optimizations -Wno-unused-function -Wno-sign-compare -I -ftree-vectorize -fomit-frame-pointer armv6 -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/gif_archive/lib/gifalloc.c -o bazel-out/armv6-opt/bin/external/gif_archive/_objs/gif/external/gif_archive/lib/gifalloc.pic.o)

可以通過修改編譯目標來避免編譯python

修改編譯目標為 tensorflow:libtensorflow_framework.so

修改build_armv6.sh 增加-I編譯選項。來避免下面的錯誤

ERROR: /home/allen/.cache/bazel/_bazel_allen/b3dc72c6218ef3f1c992e04386ed352b/external/png_archive/BUILD.bazel:8:1: C++ compilation of rule '@png_archive//:png' failed (Exit 1): gcc failed: error executing command

  (cd /home/allen/.cache/bazel/_bazel_allen/b3dc72c6218ef3f1c992e04386ed352b/execroot/org_tensorflow && \

  exec env - \

    PATH=/home/allen/bin:/home/allen/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/allen/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:/home/allen/bin \

    PWD=/proc/self/cwd \

  /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=2' -fstack-protector -Wall -Wl,-z,-relro,-z,now -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -isystem /usr/include -g0 -O3 -DNDEBUG -ffunction-sections -fdata-sections -MD -MF bazel-out/host/bin/external/png_archive/_objs/png/external/png_archive/pngpread.d -iquote external/png_archive -iquote bazel-out/host/genfilesexternal/png_archive -iquote external/zlib_archive -iquote bazel-out/host/genfiles/external/zlib_archive -iquote external/bazel_tools -iquote bazel-out/host/genfiles/external/bazel_tools -isystem external/png_archive -isystem bazel-out/host/genfiles/external/png_archive -isystem bazel-out/host/bin/external/png_archive -isystem external/zlib_archive -isystem bazel-out/host/genfiles/external/zlib_archive -isystem bazel-out/host/bin/external/zlib_archive -g0 '-march=native' -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/png_archive/pngpread.c -o bazel-out/host/bin/external/png_archive/_objs/png/external/png_archive/pngpread.o)

In file included from ——:

external/png_archive/pngpriv.h:911:4: error: #error ZLIB_VERNUM != PNG_ZLIB_VERNUM "-I (include path) error: see the notes in pngpriv.h"

#  error ZLIB_VERNUM != PNG_ZLIB_VERNUM \

    ^

INFO: Elapsed time: 558.417s, Critical Path: 13.79s

INFO: 999 processes: 999 local.

FAILED: Build did NOT complete successfully

這樣就可以編譯完成。