ctuning / ck-tensorflow

Collective Knowledge components for TensorFlow (code, data sets, models, packages, workflows):
http://cKnowledge.org
BSD 3-Clause "New" or "Revised" License
93 stars 26 forks source link

Building TFLite 1.13.1 fails due to dlsym linking error #106

Closed psyhtest closed 5 years ago

psyhtest commented 5 years ago

Building TFLite 1.13.1 fails on Ubuntu 18.04 with Android NDK r13b (installed via apt install google-android-ndk-installer) as follows:

$ ck install package:lib-tflite-1.13.1-src-static --target_os=android24-arm64
...
         /home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a  -lstdc++ -lpthread -lm -lz
/home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a(nnapi_delegate.o): In function `tflite::NNAPIAllocation::~NNAPIAllocation()':
nnapi_delegate.cc:(.text+0x93): undefined reference to `dlsym'
/home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a(nnapi_delegate.o): In function `tflite::NNAPIAllocation::~NNAPIAllocation()':
nnapi_delegate.cc:(.text+0x1f3): undefined reference to `dlsym'
/home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a(nnapi_delegate.o): In function `tflite::NNAPIAllocation::NNAPIAllocation(char const*, tflite::ErrorReporter*)':
nnapi_delegate.cc:(.text+0x46b): undefined reference to `dlsym'
/home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a(nnapi_delegate.o): In function `tflite::NNAPIDelegate::~NNAPIDelegate()':
nnapi_delegate.cc:(.text+0x64b): undefined reference to `dlsym'
nnapi_delegate.cc:(.text+0x6bf): undefined reference to `dlsym'
/home/anton/CK_TOOLS/lib-tflite-src-static-1.13.1-android-ndk-4.9.x-android24-arm64/src/tensorflow/lite/tools/make/gen/ANDROID_x86_64/lib/libtensorflow-lite.a(nnapi_delegate.o):nnapi_delegate.cc:(.text+0xaef): more undefined references to `dlsym' follow
collect2: error: ld returned 1 exit status

It looks like we need to add -ldl to the linking command.

If that fails, we can try -Wl,--no-as-needed -ldl.

psyhtest commented 5 years ago

I know how I would do that for a program:

  "extra_ld_vars": "$<<CK_EXTRA_LIB_DL>>$",

but how about for a package?

gfursin commented 5 years ago

I believe you should be able to use ${CK_EXTRA_LIB_DL} in package scripts... If these vars are resolved via dependencies, they should be available everywhere ...

psyhtest commented 5 years ago

Thanks @gfursin! I've resolved this issue as you suggested.

It's turned out that TFLite 1.13.1 also needs to be patched for Android. This removes one extra subdir, which wasn't there for TFLite 0.1.17. Alternatively, we could modify the installation script and packages, but this would require more changes.