0

I'm Trying to install TensorFlow on ARM Board (my platform is: ODROID XU4) By cross compiling using bazel and linaro compiler. I have done this steps:

  1. Download Linaro 4.9.4 for armeabihf
  2. Adding This lines to WORKSPACE file
new_local_repository(
    name = 'toolchain_target_arm_linux_gnueabihf',
    path = '/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf',
    build_file = 'arm-compiler/cross_toolchain_target_arm_linux_gnueabihf_host_x86-64.BUILD'

  1. And creating CROSSTOOL, BUILD and cross_toolchain_target_arm_linux_gnueabi_host_x86-64.BUILD files as you seen bottom:
  • arm-compile/BUILD :
package(default_visibility = ["//visibility:public"])

cc_toolchain_suite(
    name = "toolchain",
    toolchains = {
        "armeabi-v7a|compiler": ":cc-compiler-armeabi",
        "k8|compiler": ":cc-compiler-local",
    },
)

filegroup(
    name = "empty",
    srcs = [],
)

filegroup(
    name = "arm_linux_all_files",
    srcs = [
        "@toolchain_target_arm_linux_gnueabi//:compiler_pieces",
    ],
)

cc_toolchain(
    name = "cc-compiler-local",
    all_files = ":empty",
    compiler_files = ":empty",
    cpu = "local",
    dwp_files = ":empty",
    dynamic_runtime_libs = [":empty"],
    linker_files = ":empty",
    objcopy_files = ":empty",
    static_runtime_libs = [":empty"],
    strip_files = ":empty",
    supports_param_files = 1,
)

cc_toolchain(
    name = "cc-compiler-armeabi",
    all_files = ":arm_linux_all_files",
    compiler_files = ":arm_linux_all_files",
    cpu = "armeabi-v7a",
    dwp_files = ":empty",
    dynamic_runtime_libs = [":empty"],
    linker_files = ":arm_linux_all_files",
    objcopy_files = "arm_linux_all_files",
    static_runtime_libs = [":empty"],
    strip_files = "arm_linux_all_files",
    supports_param_files = 1,
)
  • arm-compile/CROSSTOOL:
major_version: "local"
minor_version: ""
default_target_cpu: "armeabi-v7a"

default_toolchain {
  cpu: "armeabi-v7a"
  toolchain_identifier: "gcc-linaro-4.9.4"
}

default_toolchain {
  cpu: "k8"
  toolchain_identifier: "local"
}

toolchain {
  abi_version: "armeabi-v7a"
  abi_libc_version: "glibc_2.19"
  builtin_sysroot: ""
  compiler: "compiler"
  host_system_name: "armeabi-v7a"
  needsPic: true
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_fission: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: true
  supports_start_end_lib: false
  supports_thin_archives: true
  target_libc: "glibc_2.19"
  target_cpu: "armeabi-v7a"
  target_system_name: "armeabi-v7a"
  toolchain_identifier: "gcc-linaro-4.9.4"

  tool_path { name: "ar" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar" }
  tool_path { name: "compat-ld" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld" }
  tool_path { name: "cpp" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-cpp" }
  tool_path { name: "dwp" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-dwp" }
  tool_path { name: "gcc" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" }
  tool_path { name: "gcov" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcov" }
  tool_path { name: "ld" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld" }
  tool_path { name: "nm" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm" }
  tool_path { name: "objcopy" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-objcopy" }
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  tool_path { name: "objdump" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-objdump" }
  tool_path { name: "strip" path: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip" }

  compiler_flag: "--sysroot=/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/"
  compiler_flag: "-mfloat-abi=hard"

  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/include"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/include/c++/4.9.4"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.9.4/include"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.9.4/include-fixed"
  cxx_builtin_include_directory: "/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include)%/c++/4.9.4"

  linker_flag: "--sysroot=/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/"
  linker_flag: "-lstdc++"
  linker_flag: "-L/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/lib"
  linker_flag: "-L/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib"
  linker_flag: "-L/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib"
  linker_flag: "-B/home/system/Clones/CrossCompileTF/toolchain/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin"

  # Anticipated future default.
  # This makes GCC and Clang do what we want when called through symlinks.
  unfiltered_cxx_flag: "-no-canonical-prefixes"
  linker_flag: "-no-canonical-prefixes"

  # Make C++ compilation deterministic. Use linkstamping instead of these
  # compiler symbols.
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""

  # Security hardening on by default.
  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
  # We need to undef it before redefining it as some distributions now have
  # it enabled by default.
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-fstack-protector"
  compiler_flag: "-fPIE"
  linker_flag: "-pie"
  linker_flag: "-Wl,-z,relro,-z,now"

  # Enable coloring even if there's no attached terminal. Bazel removes the
  # escape sequences if --nocolor is specified.
  compiler_flag: "-fdiagnostics-color=always"

    # All warnings are enabled. Maybe enable -Werror as well?
  compiler_flag: "-Wall"
  # Enable a few more warnings that aren't part of -Wall.
  compiler_flag: "-Wunused-but-set-parameter"
  # But disable some that are problematic.
  compiler_flag: "-Wno-free-nonheap-object" # has false positives

  # Keep stack frames for debugging, even in opt mode.
  compiler_flag: "-fno-omit-frame-pointer"

  # Stamp the binary with a unique identifier.
  linker_flag: "-Wl,--build-id=md5"
  linker_flag: "-Wl,--hash-style=gnu"

  compilation_mode_flags {
    mode: DBG
    # Enable debug symbols.
    compiler_flag: "-g"
  }
  compilation_mode_flags {
    mode: OPT

    # No debug symbols.
    # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
    # even generally? However, that can't happen here, as it requires special
    # handling in Bazel.
    compiler_flag: "-g0"

    # Conservative choice for -O
    # -O3 can increase binary size and even slow down the resulting binaries.
    # Profile first and / or use FDO if you need better performance than this.
    compiler_flag: "-O2"

    # Disable assertions
    compiler_flag: "-DNDEBUG"

    # Removal of unused code and data at link time (can this increase binary size in some cases?).
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"
  }
}

toolchain {
  toolchain_identifier: "local"
  abi_libc_version: "local"
  abi_version: "local"
  builtin_sysroot: ""
  compiler: "compiler"
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-D_FORTIFY_SOURCE=2"
  compiler_flag: "-fstack-protector"
  compiler_flag: "-Wall"
  compiler_flag: "-Wl,-z,-relro,-z,now"
  compiler_flag: "-B/usr/bin"
  compiler_flag: "-B/usr/bin"
  compiler_flag: "-Wunused-but-set-parameter"
  compiler_flag: "-Wno-free-nonheap-object"
  compiler_flag: "-fno-omit-frame-pointer"
  cxx_builtin_include_directory: "/usr/include/c++/5"
  cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu/c++/5"
  cxx_builtin_include_directory: "/usr/include/c++/5/backward"
  cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/5/include"
  cxx_builtin_include_directory: "/usr/local/include"
  cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed"
  cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu"
  cxx_builtin_include_directory: "/usr/include"
  cxx_flag: "-std=c++0x"
  host_system_name: "local"
  linker_flag: "-lstdc++"
  linker_flag: "-lm"
  linker_flag: "-Wl,-no-as-needed"
  linker_flag: "-B/usr/bin"
  linker_flag: "-B/usr/bin"
  linker_flag: "-pass-exit-codes"
  needsPic: true
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  supports_fission: false
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: false
  supports_start_end_lib: false
  supports_thin_archives: false
  target_cpu: "k8"
  target_libc: "local"
  target_system_name: "local"
  unfiltered_cxx_flag: "-fno-canonical-system-headers"
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
  tool_path {name: "ar" path: "/usr/bin/ar" }
  tool_path {name: "cpp" path: "/usr/bin/cpp" }
  tool_path {name: "dwp" path: "/usr/bin/dwp" }
  tool_path {name: "gcc" path: "/usr/bin/gcc" }
  tool_path {name: "gcov" path: "/usr/bin/gcov" }
  tool_path {name: "ld" path: "/usr/bin/ld" }
  tool_path {name: "nm" path: "/usr/bin/nm" }
  tool_path {name: "objcopy" path: "/usr/bin/objcopy" }
  tool_path {name: "objdump" path: "/usr/bin/objdump" }
  tool_path {name: "strip" path: "/usr/bin/strip" }

  compilation_mode_flags {
    mode: DBG
    compiler_flag: "-g"
  }
  compilation_mode_flags {
    mode: OPT
    compiler_flag: "-g0"
    compiler_flag: "-O2"
    compiler_flag: "-DNDEBUG"
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"
  }
  linking_mode_flags { mode: DYNAMIC }
}
  • arm-compile/cross_toolchain_target_arm_linux_gnueabi_host_x86-64.BUILD :
package(default_visibility = ['//visibility:public'])

filegroup(
  name = 'gcc',
  srcs = [
    'bin/arm-linux-gnueabi-gcc',
  ],
)

filegroup(
  name = 'ar',
  srcs = [
    'bin/arm-linux-gnueabi-ar',
  ],
)

filegroup(
  name = 'ld',
  srcs = [
    'bin/arm-linux-gnueabi-ld',
  ],
)

filegroup(
  name = 'nm',
  srcs = [
    'bin/arm-linux-gnueabi-nm',
  ],
)

filegroup(
  name = 'objcopy',
  srcs = [
    'bin/arm-linux-gnueabi-objcopy',
  ],
)

filegroup(
  name = 'objdump',
  srcs = [
    'bin/arm-linux-gnueabi-objdump',
  ],
)

filegroup(
  name = 'strip',
  srcs = [
    'bin/arm-linux-gnueabi-strip',
  ],
)

filegroup(
  name = 'as',
  srcs = [
    'bin/arm-linux-gnueabi-as',
  ],
)

filegroup(
  name = 'compiler_pieces',
  srcs = glob([
    'arm-linux-gnueabi/**',
    'libexec/**',
    'lib/gcc/arm-linux-gnueabi/**',
    'include/**',
  ]),
)

filegroup(
  name = 'compiler_components',
  srcs = [
    ':gcc',
    ':ar',
    ':ld',
    ':nm',
    ':objcopy',
    ':objdump',
    ':strip',
    ':as',
  ],
) 
  1. Run this Command:
bazel build --crosstool_top=//arm-compiler:toolchain --cpu=armeabi-v7a --config=opt -s //tensorflow:libtensorflow_framework.so

Unfortunately I got Error after this command, Error is:

ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:23:1: //arm-compiler:cc-compiler-local: no such attribute 'dynamic_runtime_libs' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:23:1: //arm-compiler:cc-compiler-local: no such attribute 'static_runtime_libs' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:23:1: //arm-compiler:cc-compiler-local: missing value for mandatory attribute 'toolchain_config' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:37:1: //arm-compiler:cc-compiler-armeabi: no such attribute 'dynamic_runtime_libs' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:37:1: //arm-compiler:cc-compiler-armeabi: no such attribute 'static_runtime_libs' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:37:1: //arm-compiler:cc-compiler-armeabi: missing value for mandatory attribute 'toolchain_config' in 'cc_toolchain' rule
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:23:1: Target '//arm-compiler:empty' contains an error and its package is in error and referenced by '//arm-compiler:cc-compiler-local'
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:3:1: Target '//arm-compiler:cc-compiler-armeabi' contains an error and its package is in error and referenced by '//arm-compiler:toolchain'
ERROR: /home/system/Clones/tensorflow-1.15.2/arm-compiler/BUILD:3:1: Target '//arm-compiler:cc-compiler-local' contains an error and its package is in error and referenced by '//arm-compiler:toolchain'
ERROR: /home/system/Clones/tensorflow-1.15.2/tensorflow/BUILD:563:1: every rule of type cc_binary implicitly depends upon the target '//arm-compiler:toolchain', but this target could not be found because of: Target '//arm-compiler:toolchain' contains an error and its package is in error
ERROR: Analysis of target '//tensorflow:libtensorflow_framework.so' failed; build aborted: Analysis failed
INFO: Elapsed time: 11.124s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (4 packages loaded, 18 targets con\
figured)

I'm Beginner in cross compiling and confused, Please Help and guide me. Thanks.

Yasin Kumar
  • 169
  • 1
  • 3
  • 14
  • doing an internet search for just `dynamic_runtime_libs` gave top 4+ listings related to `bazel`. Did you look at any of those? It seems to be a problem others are having, so if no one answers here, best to check those links and find the most active thread. Good luck. – shellter Aug 16 '20 at 18:59
  • Hi @shellter, Thanks for attention. Yes, I searched about it, but all of them not related to my issue. – Yasin Kumar Aug 16 '20 at 20:42
  • Hello @shellter, If is possible for ypu guide me about this problem. I asked some question about this (compiling TF for odroid) and not answered anyone. – Yasin Kumar Aug 17 '20 at 17:17
  • 1
    Sorry, I have zero experience with cross-compiling and only occasional work with compiling projects. Recently there was a thread here where the advice from a user name I recognized and respected said that cross-compiling is very hard to get right and really a top-order skill in software development. (I'm not there ;-) ) ... Their advice was to get access to the target hardware and compile it there. Getting a native compile to work can be a challenge, so I second that advice. Sorry I can't be of more help. Good luck! – shellter Aug 17 '20 at 20:23
  • @shellter. More Thanks for attention, I tried native, but in this method also i got some error that asked here but anyone answered same for this problem. Probably I have fault in asking or some reason my questions are without answer and comment. ): – Yasin Kumar Aug 17 '20 at 20:52
  • Did you see https://stackoverflow.com/questions/46653465/tensorflow-compilation-on-odroid-xu4 ? – shellter Aug 17 '20 at 21:23
  • @shellter, Yes. but this build python package and i need c++ API and I am success in TensorFlow 1.13 but this fail for TF 1.15 – Yasin Kumar Aug 18 '20 at 05:31
  • Are you still stuck? I'd consider putting a bounty on one of your questions, but I would recommend that you clean up one Q related to native compiling on the Odroid and delete the others (maybe leave this one too). This Q is good, as it has the most detail, but how much of it is related to cross-compiling? I would rather remove that part of the problem, as I mentioned above, cross-compiling is super-extra-difficult. Busy now, will check back in an hour or so. – shellter Aug 18 '20 at 12:27

0 Answers0