Re: Bionic linker's LD_LIBRARY_PATH limitation

916 views
Skip to first unread message

David Turner

unread,
Aug 26, 2012, 3:22:57 AM8/26/12
to andro...@googlegroups.com


On Sat, Aug 25, 2012 at 1:18 AM, Ilya Konstantinov <ilya.kon...@gmail.com> wrote:
Hey,

I've pretty new to NDK (and Android) development, and here's something that kept me wondering.

My code is pretty large and spans many libraries, and not before long I've stumbled upon the need to manually resolve library dependencies with calls to System.loadLibrary (e.g. as described in CPLUSPLUS-SUPPORT.html).

I've looked naively at bionic's linker/linker.cpp and saw the inherent limitation that LD_LIBRARY_PATH is being parsed only at startup, rather than on every library load. Is it just for performance (is that significant performance gain?) or is there some other limitation I've overlooked in my naivete?


No, this is perfectly normal, and behaves *exactly* the same on a Linux distro.
 
BTW, I know there's no way to change environment variables from Java, but a) that could be easily worked around, and b) I believe most users would be satisfied with simply their app's lib to be in the library path.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/FtsEfik6LY0J.
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.


Ilya Konstantinov

unread,
Aug 26, 2012, 1:54:29 PM8/26/12
to android-ndk
On Aug 26, 10:22 am, David Turner <di...@android.com> wrote:
> No, this is perfectly normal, and behaves *exactly* the same on a Linux
> distro.

Oh, I never realized, but it makes sense.

I guess what I'm trying to ask is why the app's nativeLibraryDir isn't
added to the LD_LIBRARY_PATH by whoever launches the app?
Compatibility? Some security consideration? Simply a TODO?

Alex Cohn

unread,
Apr 2, 2013, 8:53:24 AM4/2/13
to andro...@googlegroups.com

Tor Lillqvist

unread,
Apr 2, 2013, 11:15:11 AM4/2/13
to andro...@googlegroups.com
As was said, LD_LIBRARY_PATH is parsed only when a program starts execution. Note that your app is *not* "a program". Your app runs in a process of its own, sure, but that process is a fork of the Zygote process and it does not exec() any new program to run, it just loads the Java code for your app. In the case of "pure native" apps, that Java code is not anything you wrote, sure (because your app is "pure native"), but it is still Java code (the NativeActivity class etc). Java code then loads any of your native libraries, when/if told to.

Android is not a "normal" Linux system. The application lifecycle is not "normal". Learn to live with it.

--tml

Reply all
Reply to author
Forward
0 new messages