Ashutosh Malviya wrote:
[...]
>  I tried to change the order of loading library (i.e. loading NativeAdd
> first and NativeC later, but android failed to load NativeAdd library,
> probably because it was not able to resolve symbol ret_mul .

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).

-- 
┌─── 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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to