3

I am trying to compile tensorflow-lite for Android running the building script, but the building process stops with this error:

/system/bin/linker: No such file or directory

I can understand how the building process works (compilation + linking) but I can not figure out why this '/system/bin/linker' is needed. This linker is not present in the SDK or NDK folder, and it is not present in the folder tree of the host computer (I am using Linux for the building process).

It looks like part of the Android file structure, but the building process should not depend on the final system structure.

The element I am trying to build is 'schema_fbs', which compiles part of the code using flatbuffers (a 3rd party dependency). The complete sentence I am using is:

bazel build \
--cxxopt='--std=c++11' \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a \
--verbose_failures \
--subcommands \
//tensorflow/contrib/lite/schema:schema_fbs

It could be caused by a testing case inside the Bazel building script (I have commented all the tests I found), but why is the linker needed? Is there something I have to do to define this 'system' folder in the compilation process?

Notes:

Target OS: Android

Host OS: Ubuntu 16.04

Used NDK: v16b (tested with v17 but it is not compatible)

Full error messages:

INFO: Analysed target //tensorflow/contrib/lite/schema:schema_fbs_srcs (0 packages loaded).
INFO: Found 1 target...
SUBCOMMAND: # //tensorflow/contrib/lite/schema:schema_fbs_srcs [action 'Generating flatbuffer files for schema_fbs_srcs: //tensorflow/contrib/lite/schema:schema_fbs_srcs']
(cd /home/user/.cache/bazel/_bazel_user/73606864f5ec4cce18dd83a6cbcd2bc2/execroot/org_tensorflow && \
  exec env - \
    LD_LIBRARY_PATH=/usr/local/lib:/home/user/Libraries/llvm-4.0.0.src/build/lib: \
    PATH=/home/user/Software/git-sizer:/home/user/Android/Sdk/platform-tools:/home/user/anaconda3/bin:/home/user/Libraries/llvm-4.0.0.src/build/bin:/home/user/bin:/home/user/repo/caffe/build/install/lib:/home/user/Software/cmake-3.10.3-Linux-x86_64/bin:::::/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; for f in tensorflow/contrib/lite/schema/schema.fbs; do bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc --no-union-value-namespacing --gen-object-api  -c -o bazel-out/armeabi-v7a-opt/genfiles/tensorflow/contrib/lite/schema $f; done')
ERROR: /home/user/Repositories/git/tensorflow/tensorflow/contrib/lite/schema/BUILD:57:1: Generating flatbuffer files for schema_fbs_srcs: //tensorflow/contrib/lite/schema:schema_fbs_srcs failed (Exit 255): bash failed: error executing command 
  (cd /home/user/.cache/bazel/_bazel_user/73606864f5ec4cce18dd83a6cbcd2bc2/execroot/org_tensorflow && \
  exec env - \
    LD_LIBRARY_PATH=/usr/local/lib:/home/user/Libraries/llvm-4.0.0.src/build/lib: \
    PATH=/home/user/Software/git-sizer:/home/user/Android/Sdk/platform-tools:/home/user/anaconda3/bin:/home/user/Libraries/llvm-4.0.0.src/build/bin:/home/user/bin:/home/user/repo/caffe/build/install/lib:/home/user/Software/cmake-3.10.3-Linux-x86_64/bin:::::/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; for f in tensorflow/contrib/lite/schema/schema.fbs; do bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc --no-union-value-namespacing --gen-object-api  -c -o bazel-out/armeabi-v7a-opt/genfiles/tensorflow/contrib/lite/schema $f; done')
/system/bin/linker: No such file or directory
Target //tensorflow/contrib/lite/schema:schema_fbs_srcs failed to build
INFO: Elapsed time: 0.572s, Critical Path: 0.02s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
goe
  • 2,272
  • 1
  • 19
  • 34
  • 1
    I'm guessing that the local cc toolchain isn't getting set up correctly, or is not installed. Could you include more of the error (e.g. what thing bazel gets stuck on trying to build)? What platform are you on? If Ubuntu or similar, have you installed these packages? https://docs.bazel.build/versions/master/install-ubuntu.html#step-1-install-required-packages – ahumesky Jun 11 '18 at 22:04
  • 1
    If you're on a mac, you may need to install xcode: https://docs.bazel.build/versions/master/install-os-x.html#step-1-install-xcode-command-line-tools – ahumesky Jun 11 '18 at 22:05
  • 1
    Also, which version of the NDK are you using? – ahumesky Jun 11 '18 at 22:09
  • I have included some info in the body of the question. The packages described in the tutorial are installed, and I have tested with standalone SDK and with the SDK downloaded by Android Studio (same for the NDK). Same error in all cases. – goe Jun 12 '18 at 09:47
  • Thanks for the additional information. Unfortunately, I wasn't able to repro the problem (bazel 0.14, ubuntu, ndk 16b). It's worth noting that I also don't have a `/system` directory. Can you also try running bazel with `--subcommands` to see which action fails? – ahumesky Jun 12 '18 at 22:31
  • Subcommand says: SUBCOMMAND: # //tensorflow/contrib/lite/schema:schema_fbs_srcs [action 'Generating flatbuffer files for schema_fbs_srcs: //tensorflow/contrib/lite/schema:schema_fbs_srcs'] – goe Jun 13 '18 at 13:55
  • Was that the full output? `--subcommands` usually outputs more than that, including the command line of the failing action. If there was more, can you paste the full output somewhere (github gist, pastbin, etc)? – ahumesky Jun 13 '18 at 14:31
  • If that was the only command that `--subcommands` reported, then that's coming from here: https://github.com/tensorflow/tensorflow/blob/master/third_party/flatbuffers/build_defs.bzl#L59 It's not clear why that would fail with this error. The flatc tool is a `cc_binary`, so maybe try building that directly? `bazel build @flatbuffers//:flatc` – ahumesky Jun 13 '18 at 14:34
  • Building flatc directly no errors are reported: "Build completed successfully" – goe Jun 13 '18 at 15:28
  • So then what was the rest of the output of `--subcommands`? Was there more? – ahumesky Jun 13 '18 at 16:37
  • I have included the entire error message in the question. – goe Jun 15 '18 at 07:11
  • Thanks, that's very helpful. The error is coming from this genrule: https://github.com/tensorflow/tensorflow/blob/8212404a47e17a0ad1822e520c990be1cd712e91/third_party/flatbuffers/build_defs.bzl#L59 From the error message, it appears that `flatc` is being compiled for armeabi-v7a, which probably won't work on your host machine. The question is why, since it appears that `flatc` is correctly listed in the `tools` of the genrule, which should compile it for host: https://github.com/tensorflow/tensorflow/blob/8212404a47e17a0ad1822e520c990be1cd712e91/third_party/flatbuffers/build_defs.bzl#L63 – ahumesky Jun 15 '18 at 18:26
  • So your error message has `flatc` under `armeabi-v7a`: "bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc". When I try to reproduce this, bazel builds flatc under the host configuration: "bazel-out/host/bin/external/flatbuffers/flatc". I tried building flatc under the android configuration with armeabi-v7a, but it failed with "error: 'to_string' is not a member of 'std'". – ahumesky Jun 15 '18 at 21:04
  • What happens when you try to build flatc with the android crosstool? `bazel build @flatbuffers//:flatc --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a --cxxopt='--std=c++11'` – ahumesky Jun 15 '18 at 21:04
  • Also, after running the build that fails with "/system/bin/linker: No such file or directory", what happens if you try to run flatc directly? i.e. running "bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc" after the build – ahumesky Jun 15 '18 at 21:12
  • When I build flatc with crosstool it finishes correctly: "Build completed successfully". – goe Jun 18 '18 at 07:11
  • When I try to run the 'flatc' file directly as suggested, the answer is the same as before: "/system/bin/linker: No such file or directory". It looks like it is correctly compiled for the target architecture (ARM), but the system is trying to run it for the host system. – goe Jun 18 '18 at 07:19
  • It's very strange that you're able to compile flatc for armeabi-v7a using the NDK, where mine fails. What's the output when you run `bazel query //external:android/crosstool --output build`? I get a `bind` rule like this: `bind( name = "android/crosstool", actual = "@androidndk//:default_crosstool", )` – ahumesky Jun 18 '18 at 20:51
  • Also, which version of tensorflow are you working with? One of the releases (1.8.0, 1.9.0, etc) or from head? If you have one of the releases, just to double check, do you have `android_sdk_repository` and `android_ndk_repository` set up in the `WORKSPACE` file? – ahumesky Jun 18 '18 at 21:19
  • It might also help to compile flatc with the NDK and pass --subcommands, to see why it's working for you but not me. If you can, try `bazel build @flatbuffers//:flatc --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a --cxxopt='--std=c++11' --subcommands` and paste the output somewhere (github gist, pastebin, etc) – ahumesky Jun 18 '18 at 21:28
  • I am using the master branch of the tensorflow repository. I have seen that the Android configuration changed recently, but I have not time right now to test this (I am a bit saturated). I will retake this ASAP. Thanks for your help. – goe Jun 21 '18 at 07:39
  • Thanks for the info. I know that this has been a lot of back and forth, so thank you for your patience. It's a strange error! – ahumesky Jun 21 '18 at 19:18

1 Answers1

1

The TensorFlow Lite AAR can also be built using:

bazel build --cxxopt='--std=c++11' -c opt --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a tensorflow/contrib/lite/java:tensorflow-lite

And you must make sure you ran ./configure and let it configure SDK and NDK for your.

Andre Hentz
  • 101
  • 2