Qt on Android with Tensorflow as 3rd party lib
-
Hello:
Currently I tried to embed tensorflow c++ lib into my app, I somehow managed to done the job on desktop and iOS, but failed on Android. The problem is the link problem as the following:
/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/lib/libtensorflow-core.a(net.o):net.cc:function tensorflow::internal::PickUnusedPortOrDie(): error: undefined reference to 'rand' /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/lib/libtensorflow-core.a(subprocess.o):subprocess.cc:function tensorflow::SubProcess::Communicate(std::string const*, std::string*, std::string*) [clone .part.5]: error: undefined reference to 'sigemptyset' /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/protobuf/lib/libprotobuf.a(strutil.o):strutil.cc:function google::protobuf::safe_strtof(char const*, float*): error: undefined reference to 'strtof' /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/protobuf/lib/libprotobuf-lite.a(strutil.o):strutil.cc:function google::protobuf::safe_strtof(char const*, float*): error: undefined reference to 'strtof' collect2: error: ld returned 1 exit status make: *** [libCrossDemo.so] Error 1 11:57:57: The process "/usr/bin/make" exited with code 2. Error while building/deploying project CrossDemo (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.8.0)) When executing step "Make"
I think this problem is because I did not reference to the std lib correctly. Could someone help me with this problem? thank you.
====
OS: macOS 10.12.3
SDK: android-21
NDK: r13b -
Hi and welcome to devnet,
How did you configure your project to link to tensorflow ?
-
Hello:
My configuration for android is as the following:
android: { CONFIG += c++11 LIBS += -L/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/lib -ltensorflow-core INCLUDEPATH += /Users/chen/Documents/Git/tensorflow \ #/Users/chen/Documents/Git/tensorflow/bazel-out/local-fastbuild/genfiles DEPENDPATH += /Users/chen/Documents/Git/tensorflow \ #/Users/chen/Documents/Git/tensorflow/bazel-out/local-fastbuild/genfiles LIBS += -L/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/protobuf/lib -lprotobuf -lprotobuf-lite #LIBS += -L/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/protobuf_ios/lib -lprotobuf-lite -lprotobuf INCLUDEPATH += /Users/chen/Documents/Git/tensorflow/ \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads/eigen \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/proto DEPENDPATH += /Users/chen/Documents/Git/tensorflow/ \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads/eigen \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/proto PROBOF_PATH = /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/protobuf/include INCLUDEPATH += $$PROTOBUF_PATH DEPENDPATH += $$PROTOBUF_PATH # libc.a LIBS += -L/Users/chen/Library/Android/android-ndk-r13b/platforms/android-21/arch-arm64/usr/lib/libc.a QMAKE_LFLAGS += -lz -lm -llog -landroid -lgnustl_static QMAKE_LFLAGS += -Wl,--allow-multiple-definition -Wl,--whole-archive QMAKE_CXXFLAGS += -std=c++11 -fno-rtti -fno-exceptions \ -fpic -O2 -mfpu=neon -DTF_LEAN_BINARY \ -DGOOGLE_PROTOBUF_NO_RTTI \ -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER #QMAKE_LFLAGS += -llog -lz #CONFIG+= static #QMAKE_LFLAGS += -static -static-libgcc #QMAKE_LFLAGS += -force_load /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_android/lib/libtensorflow-core.a }
Comparably with the iOS configuration, which kind of works fine:
ios: { LIBS += -L/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/lib -ltensorflow-core LIBS += -L/Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/protobuf_ios/lib -lprotobuf-lite -lprotobuf INCLUDEPATH += /Users/chen/Documents/Git/tensorflow/ \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios/protobuf/src \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios/eigen \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/proto DEPENDPATH += /Users/chen/Documents/Git/tensorflow/ \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios/protobuf/src \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/downloads_ios/eigen \ /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/proto CONFIG -= bitcode QMAKE_LFLAGS += -force_load /Users/chen/Documents/Git/tensorflow/tensorflow/contrib/makefile/gen_ios/lib/libtensorflow-core.a LIBS += -framework Accelerate # Copy models into bundle APP_PB_FILES.files = $$PWD/Models/graph_binary.pb APP_PB_FILES.path = Models QMAKE_BUNDLE_DATA += APP_PB_FILES }
-
Which version of the SDK/ndk are you using ?
-
The versions of SDK/NDK are as the following:
SDK: android-21
NDK: r13bOfficially from Google
@LeoChen you should use NDK r10e (https://wiki.qt.io/Qt_5.8_Tools_and_Versions)
-
@LeoChen you should use NDK r10e (https://wiki.qt.io/Qt_5.8_Tools_and_Versions)
@ekkescorner Mysteriously solved after several failure, thanks a lot!
-
You can also find a guide how to build and integrate TensorFlow with Qt and V-Play here:
https://v-play.net/cross-platform-development/machine-learning-add-image-classification-for-ios-and-android-with-qt-and-tensorflowThe example project of this guide includes Image Classification and Object Recognition features based on neural network models, which you can control from QML:
Tensorflow provides the machine learning framework, whereas V-Play and Qt facilitate the app deployment to multiple platforms: desktop and mobile.