How can I use Shared library in C Native code

80 views
Skip to first unread message

srandroidbeginer

unread,
Oct 31, 2009, 8:38:51 AM10/31/09
to android-ndk
Hi,
I want to use third party shared library in my C Native code. I tried
dlopen("/data/data/com.example.HelloJni/lib/libabc.so", RTLD_LAZY);
but giving error. Do I need to load explicitly through dlopen?

Why I am not able to load the library from C code. I apreciate your
help.

Thanks
Srikanth

David Turner

unread,
Oct 31, 2009, 6:29:47 PM10/31/09
to andro...@googlegroups.com
what is the error reported by dlerror() exactly ?
how was the library generated ?


--

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.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.



karl-heinz reichel

unread,
Nov 18, 2009, 5:26:36 AM11/18/09
to andro...@googlegroups.com
Hi,
I think You can only load shared libs with dlopen, when they are located in /system/lib ..

regards 
karl-heinz


2009/10/31 srandroidbeginer <sro...@gmail.com>

Dianne Hackborn

unread,
Nov 18, 2009, 5:47:50 PM11/18/09
to andro...@googlegroups.com
On Sat, Oct 31, 2009 at 4:38 AM, srandroidbeginer <sro...@gmail.com> wrote:
dlopen("/data/data/com.example.HelloJni/lib/libabc.so", RTLD_LAZY);

Please never ever hard-code a path like that.  There are Java APIs to get the path to your data.  I can guarantee that if you use a hard-coded path that your app will break in certain situations in the future.

--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

lath...@gmail.com

unread,
Jan 11, 2010, 12:54:43 AM1/11/10
to android-ndk
Hi Dianne,

> Please never ever hard-code a path like that. There are Java APIs to get
> the path to your data.

Could you please suggest us those APIs & how they are used to get the
path of the libs?


That will be very useful for most of us.

thanks a lot
Latha


On Nov 19 2009, 3:47 am, Dianne Hackborn <hack...@android.com> wrote:


> On Sat, Oct 31, 2009 at 4:38 AM, srandroidbeginer <srou...@gmail.com> wrote:
> > dlopen("/data/data/com.example.HelloJni/lib/libabc.so", RTLD_LAZY);
>
> Please never ever hard-code a path like that.  There are Java APIs to get
> the path to your data.  I can guarantee that if you use a hard-coded path
> that your app will break in certain situations in the future.
>
> --
> Dianne Hackborn
> Android framework engineer

> hack...@android.com

Reply all
Reply to author
Forward
0 new messages