It is a limitation of the system.
In a nutshell, the dynamic linker doesn't know anything about your application (e.g. where its libraries live), it only knows about the LD_LIBRARY_PATH value that was set when the process was created. When you start an Android application, you really fork the Zygote process, you don't create a new one, so the library search path is the initial one and doesn't include your app's /data/data/<pkgname>/lib/ directory, where your native libraries live. This means that dlopen("libfoo.so") will not work, because only /system/lib/libfoo.so will be searched.
When you call System.loadLibrary("foo") from Java, the VM framework knows the application's directory, so it can translate "foo" into "/data/data/<pkgname>/lib/libfoo.so", then call dlopen() with this full path, which will work.
It libfoo.so references "libbar.so", then the dynamic linker will not be able to find the latter.
Add to this that even if you update LD_LIBRARY_PATH from native code, the dynamic linker will not see the new value. For various low-level reasons, the dynamic linker contains its own copy of the program's environment as it was when the process was created (not forked). And there is simply no way to update it from native code. This is by design, and changing this would have drastic security constraints. For the record, this is also how the Linux dynamic linker works, this forces any program that needs a custom library search path to use a wrapper script to launch its executable (e.g. Firefox, Chrome and many others).
We could hack the dynamic linker and framework to solve this in various secure ways, but at the moment loading the libraries in reverse order doesn't appear as a big bottleneck.
Sorry, but I don't think there is reliable work-around. Some people have been playing with rpath to embed the full path of dependent libraries in the .so itself, but this is no guaranteed to work (e.g. it will break if you move the app to the SD Card, because now the libraries are in a directory with a completely different path, most of it random iirc).
Thank you,
François
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.