Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt on Android with Tensorflow as 3rd party lib
Forum Updated to NodeBB v4.3 + New Features

Qt on Android with Tensorflow as 3rd party lib

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 4 Posters 4.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeoChen
    wrote on 16 Feb 2017, 03:58 last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Feb 2017, 22:41 last edited by
      #2

      Hi and welcome to devnet,

      How did you configure your project to link to tensorflow ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeoChen
        wrote on 17 Feb 2017, 03:00 last edited by LeoChen
        #3

        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
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Feb 2017, 21:24 last edited by
          #4

          Which version of the SDK/ndk are you using ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LeoChen
            wrote on 18 Feb 2017, 02:43 last edited by
            #5

            The versions of SDK/NDK are as the following:

            SDK: android-21
            NDK: r13b

            Officially from Google

            E 1 Reply Last reply 18 Feb 2017, 16:41
            0
            • L LeoChen
              18 Feb 2017, 02:43

              The versions of SDK/NDK are as the following:

              SDK: android-21
              NDK: r13b

              Officially from Google

              E Offline
              E Offline
              ekkescorner
              Qt Champions 2016
              wrote on 18 Feb 2017, 16:41 last edited by
              #6

              @LeoChen you should use NDK r10e (https://wiki.qt.io/Qt_5.8_Tools_and_Versions)

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
              5.15 --> 6.8 https://t1p.de/ekkeChecklist
              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

              L 1 Reply Last reply 20 Feb 2017, 10:45
              0
              • L Offline
                L Offline
                LeoChen
                wrote on 20 Feb 2017, 03:47 last edited by
                #7

                Thank you for your information, I tried but still get the same error.

                1 Reply Last reply
                0
                • E ekkescorner
                  18 Feb 2017, 16:41

                  @LeoChen you should use NDK r10e (https://wiki.qt.io/Qt_5.8_Tools_and_Versions)

                  L Offline
                  L Offline
                  LeoChen
                  wrote on 20 Feb 2017, 10:45 last edited by
                  #8

                  @ekkescorner Mysteriously solved after several failure, thanks a lot!

                  1 Reply Last reply
                  0
                  • GTDevG Offline
                    GTDevG Offline
                    GTDev
                    wrote on 5 Sept 2018, 13:03 last edited by
                    #9

                    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-tensorflow

                    alt text

                    The example project of this guide includes Image Classification and Object Recognition features based on neural network models, which you can control from QML:

                    alt text

                    Tensorflow provides the machine learning framework, whereas V-Play and Qt facilitate the app deployment to multiple platforms: desktop and mobile.

                    Senior Developer at Felgo - https://felgo.com/qt

                    Develop mobile Apps for iOS & Android with Qt
                    Felgo is an official Qt Technology Partner

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved