I'm quite sure this problem is due to the incompatibility of the
libraries. So, I advise you to hit ldd, and check the libraries it loads.
Thanks,
Diluka.
This error usually shows up for unresolved symbols.
[...]
> System.loadLibrary("NativeC");
> System.loadLibrary("NativeAdd");
It's entirely possible that System.loadLibrary() doesn't allow libraries
to see symbols defined in other libraries, so you won't be able to have
NativeAdd depend on NativeC. However, I suspect your main problem is...
[...]
> #include <iostream>
iostream could well be trying to pull in symbols that the very
stripped-down libc supported by the dalvik executable won't have.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup
>>Ashutosh wrote:
>>[...]
> INFO/dalvikvm(1185): Unable to dlopen(/system/lib/libNativeCpp.so):>>This error usually shows up for unresolved symbols.
> Cannot find library
>>[...]
> System.loadLibrary("NativeC");>>It's entirely possible that System.loadLibrary() doesn't allow libraries
> System.loadLibrary("NativeAdd");
>>to see symbols defined in other libraries, so you won't be able to have
>>NativeAdd depend on NativeC. However, I suspect your main problem is...
>>[...]
> #include <iostream>
>>iostream could well be trying to pull in symbols that the very
>>stripped-down libc supported by the dalvik executable won't have.
The main problem which you will need to address is that the libraries we
use inside from your *.so files, will need the default linux linker
(ld-linux.so*), and some other *.so files. So we can get rid of the
problem of not having libraries in the Android platform by copying it
into the Android platform with other libraries and setting rpath
variable while compiling. Then all the libraries+programs you run on
Android will run successfully. They you also can run a C/C++ binary from
Android platform (using it's console).
But remember your all capabilities end when you try on using JNI, if you
have a look into the dalvik VM (I actually have forgotten the binary
name correspond to the vm inside Android), it will use a custom linker
(also do not remember the name, you can do a ldd after copying that
binary into the local machine-actually not ldd, but I guess
arm-none-linux-gnueabi-ldd as far as I remember). Then you will realize
that it will load a custom linker (NOT ld-linux as in ALL the other
Linux distributions), so when you see that point it's almost done buddy.
You can't load your libraries which you copied from cross-platform
development system, and the ones you built using that platform.
But I guess for very very simple *.so files, we can load from JNI, which
might have the neccessary symbols in libraries that included with
Android. Basically for me I wasted a lot of time doing these things.
My suggestion for you is that, do not go for serious development using
native libraries until the list of API functions in Android becomes
available. Else you will soon meet lots of troubles.
Thanks,
Diluka.
That's not quite what I meant. System.loadLibrary() will ultimately call
the C system function dlopen() to do the work. When you call dlopen(),
you tell it that the symbols in the library are public (which means
other libraries can see them), or private (which means other libraries
can't see them). We don't know what option System.loadLibrary() is
using. I suspect it's going to be using the private option, which means
you won't be able to have one library refer to symbols in another one.
[...]
> Removing iostream and using 'extern "C"' made the library which has only
> one undefined symbol '__aeabi_unwind_cpp_pr0' which is available in
> /system/lib
Unfortunately it's not quite that easy...
My experimentation seems to show that only the symbols used in the
dalvik executable are available to JNI libraries. Since dalvik only uses
some of the symbols from the run-time library, that means you only have
those available to play with. (Remember this stuff is a hack!)
In my experience only the very simplest C code works reliably, and
you're probably going to have to implement workarounds for missing
run-time functions. In addition, dlopen() has some very serious bugs in
it which means that some code will simply be loaded incorrectly. (See
#599 on the bug tracker at http://code.google.com/p/android/issues/list
--- you would not *believe* the workaround I had to do to get around this.)
> But does this mean that all that big chunk of C and C++ source code that
> I wanted to port to android will not be possible ?
I would suggest not wasting time trying to make this work for now. For
my project, I did enough proof-of-concept code to verify that it *would*
all work, eventually, and then left it at that. Hopefully the next SDK
version will have some of these things fixed (particularly #599, which
is very critical).