[SOLVED] Add external C lib (zeromq) to project that will run on android
-
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 :) -
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.
-
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 :)
-
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.
-
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...
-
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@ -
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.
-
Hi,
Are you linking against an ARM version of libqmq when you build for android ?
-
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