I'm experimenting with native libs cross compiled from ubuntu. What I really want is to be able to compile my c++ libraries and use them in a Xamarin.Android app.
First, I have the arm gcc compiler: arm-linux-gnueabi-gcc
. I have a simple lib (libmr.so) that has one function void Print();
that prints something to the console. I'm compiling with:
arm-linux-gnueabi-gcc -Wall -shared -o libmr.so mr.c
When inspecting it using file libmr.so
everything seems to be good. However when I'm including it with my android app and try to load it, it is as if it doesn't exist. I'm certain it is there, the path is absolutely correct as I tried to load another lib (libmonodroid.so
) from the same folder and it worked.
I tried inspecting both libs to find some kind of a difference:
$ objdump -x libmr.so | grep NEEDED
NEEDED libc.so.6
$ objdump -x libmonodroid.so | grep NEEDED
NEEDED libc.so
... (in addition to other libs)
This is the only difference I'm finding between the two. libmonodroid.so
loads properly but libmr.so
acts as if it doesn't exist. (I'm using dlopen
to load a lib)
EDIT:
I built an executable using the same toolchain, gave me a clue:
- Static linking with libc:
arm-linux-gnueabi-gcc -Wall -o hi source.c -static
. Pushedhi
to my android devices and executed it withadb
. Result: SUCCESS! - Dynamic linking with libc:
arm-linux-gnueabi-gcc -Wall -o hi source.c
. Result: it's not even there! Meaning./hi
gives/system/bin/sh: ./hi: not found
although it's absolutely there.
So, looks like libc is really the culprit? Maybe I need to link dynamically with not libc.so.6
but with libc.so
just like libmonodroid.so
is doing?