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. [SOLVED] Add external C lib (zeromq) to project that will run on android
QtWS25 Last Chance

[SOLVED] Add external C lib (zeromq) to project that will run on android

Scheduled Pinned Locked Moved Mobile and Embedded
14 Posts 3 Posters 13.2k Views
  • 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.
  • D Offline
    D Offline
    DerMas
    wrote on last edited by
    #1

    I'd like to use zeromq in my qt application. In order to use it, I added the following line to my *.pro file:

    @LIBS += -lzmq@

    Then I made a small zmq subscriber example:

    @
    #include <zmq.h>
    [...]
    void *context = zmq_ctx_new ();
    void *subscriber = zmq_socket (context, ZMQ_SUB);
    zmq_connect (subscriber, "tcp://localhost:5555");
    zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0);
    [...]
    @

    When I compile it as a linux desktop application, everything works fine (running and compiling (gcc) with ubuntu). But when I try to run it on Android, I get compilation errors:

    @ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lzmq
    ../zmq/main.cpp:18: error: undefined reference to 'zmq_ctx_new'
    ../zmq/main.cpp:19: error: undefined reference to 'zmq_socket'
    ../zmq/main.cpp:20: error: undefined reference to 'zmq_connect'
    ../zmq/main.cpp:21: error: undefined reference to 'zmq_setsockopt'
    collect2: error: ld returned 1 exit status
    make: *** [libzmq.so] Error 1
    14:49:58: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project zmq (kit: Android for arm (GCC 4.8, Qt 5.1.0))@

    What are the necessary steps in order to use zeromq on the android plattform?
    Thanks in advance for any helpful reply :)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Moster
      wrote on last edited by
      #2

      For example, what Im doing with opencv is this. I include the libs and includes manually. (in the .pro file)

      @INCLUDEPATH += $$PWD/../../../NVPACK/OpenCV-2.4.5-Tegra-sdk-r2/sdk/native/jni/include/opencv/
      INCLUDEPATH += $$PWD/../../../NVPACK/OpenCV-2.4.5-Tegra-sdk-r2/sdk/native/jni/include/opencv2/

      LIBS += -L$$PWD/../../../NVPACK/OpenCV-2.4.5-Tegra-sdk-r2/sdk/native/libs/tegra3/
      -lopencv_contrib
      -lopencv_legacy \ ...@

      PWD is the working directory of my app and from there I move to the right place. Its important that I let QtCreator bundle the libraries into the apk. I think it wouldnt work with ministro.

      edit: also works with ministro.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerMas
        wrote on last edited by
        #3

        Thanks for the hint. But again configuring it that way works with compiling for the desktop, but not for android.

        What I did:

        I replaced the LIBS configuration I posted aboth with this:

        @INCLUDEPATH += $$PWD/../../../../../usr/local/include
        DEPENDPATH += $$PWD/../../../../../usr/local/include
        LIBS += $$PWD/../../../../../usr/local/lib/libzmq.a@

        Now I get the following error:

        @ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/qtappzmq/../../../../../usr/local/lib/libzmq.a(libzmq_la-zmq.o): incompatible target
        ../zmq/main.cpp:18: error: undefined reference to 'zmq_ctx_new'
        ../zmq/main.cpp:19: error: undefined reference to 'zmq_socket'
        ../zmq/main.cpp:20: error: undefined reference to 'zmq_connect'
        ../zmq/main.cpp:21: error: undefined reference to 'zmq_setsockopt'
        collect2: error: ld returned 1 exit status
        make: *** [libzmq.so] Error 1
        15:31:50: The process "/usr/bin/make" exited with code 2.@

        I should add, that I am quite a newbie to the whole c library stuff. So if you think I have missed something simple, dont hesitate and point to it :)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Moster
          wrote on last edited by
          #4

          Try it like this

          @ INCLUDEPATH += $$PWD/../../../../../usr/local/include
          DEPENDPATH += $$PWD/../../../../../usr/local/include
          LIBS += $$PWD/../../../../../usr/local/lib/ -lzmq
          @

          Btw, is zeromq supposed to work on android?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerMas
            wrote on last edited by
            #5

            Like that it doesnt work with the desktop and with the android compilation :)

            I get the following error while compiling for desktop:

            @/usr/bin/ld: cannot find /home/qtappzmq/../../../../../usr/local/lib/: File format not recognized
            collect2: ld returned 1 exit status
            make: *** [zmq] Error 1
            15:41:52: The process "/usr/bin/make" exited with code 2.@

            And this error while compiling for android:

            @ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: fatal error: /home/qtappzmq/../../../../../usr/local/lib/: pread failed: Is a directory
            collect2: error: ld returned 1 exit status
            make: *** [libzmq.so] Error 1
            15:45:46: The process "/usr/bin/make" exited with code 2.@

            bq. Btw, is zeromq supposed to work on android?

            I naivly thought it should, because its just some c code.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Moster
              wrote on last edited by
              #6

              Sorry, I didnt see that you were already using an absolute path.

              It should look like this then:

              @ INCLUDEPATH += /usr/local/include
              DEPENDPATH += /usr/local/include
              LIBS += /usr/local/lib/ -lzmq
              @

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DerMas
                wrote on last edited by
                #7

                Getting the same errors for desktop and android :/

                -But I found a source for zmq and android. Seems like I have to make a special build for android:-
                -http://zeromq.org/build:android-

                edit: Ok that was about building a jar in order to use zeromq, but since I'd like to use it directly as a C lib with my QT app it might work just like that, if I could only configure it correctly...

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Moster
                  wrote on last edited by
                  #8

                  Are you sure that its the same error? I think it should be at least a little bit different.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DerMas
                    wrote on last edited by
                    #9

                    It is the same error, but the dir is now the absolute and not the relative one.

                    Now it is:
                    @/usr/bin/ld: cannot find /usr/local/lib/: File format not recognized@ instead of
                    @/usr/bin/ld: cannot find /home/qtappzmq/../../../../../usr/local/lib/: File format not recognized@

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Moster
                      wrote on last edited by
                      #10

                      Like this it builds at least.

                      @LIBS += /usr/local/lib/libzmq.a

                      INCLUDEPATH += /usr/local/include
                      DEPENDPATH += /usr/local/include

                      PRE_TARGETDEPS += /usr/local/lib/libzmq.a@

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        DerMas
                        wrote on last edited by
                        #11

                        Yap, it builds for the desktop compile target like that, but for the android compile target I get the "incompatible target" error again, which I showed detailed in my second post.

                        I think there is something special to do for the android compile target, that I forget.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          Are you linking against an ARM version of libqmq when you build for android ?

                          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
                          • M Offline
                            M Offline
                            Moster
                            wrote on last edited by
                            #13

                            Ye, thats what I already asked. You cant expect a desktop lib to work on android. The libraby might be using some other libraries that arent available on android.

                            http://zeromq.org/build:android
                            It creates some libraries and a java wrapper. Maybe you can just bind the libs to your app

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DerMas
                              wrote on last edited by
                              #14

                              head -> wall I tried to link to the libzmq that i built for ubuntu. That sounds like reason for the "incompatible" error ;) Thanks!

                              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