dlopen

520 views
Skip to first unread message

krupa

unread,
Mar 3, 2011, 6:26:35 AM3/3/11
to android-ndk
Hi All,

I have built a library .so ( not through Android ndk, through linux
makefile ) for ARM target and i am trying to access this in sample
application using C on ubuntu linux machine . I am using dlopen method
to access the library but i am getting the error , cant open the
shared object, No such file or directory. So i want to know is there
any dlopen equivalent method to access the library for ARM target? Pls
help

sanjay kumar

unread,
Mar 3, 2011, 10:04:20 PM3/3/11
to andro...@googlegroups.com
Hi ,
When you make a .so in linux it is done through GNU libc while for ARM target you need to build through bionic libc as bionic libc do not have all the libraries as in GNU libc.
For this problem what you can do is to make a Android.mk file for building the .so.


Regards,
Sanjay


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


krupa

unread,
Mar 3, 2011, 10:36:37 PM3/3/11
to android-ndk
Hi Sanjay,

I have created the library using arm cross compiler toolchain. I have
used ARM related commands for compilation.

I dont want to use Android. mk file as of now, so what can be done
through linux to solve this problem ??

Regards,
Krupa

On Mar 4, 8:04 am, sanjay kumar <sanjaybit...@gmail.com> wrote:
> Hi ,
> When you make a .so in linux it is done through GNU libc while for ARM
> target you need to build through bionic libc as bionic libc do not have all
> the libraries as in GNU libc.
> For this problem what you can do is to make a Android.mk file for building
> the .so.
>
> Regards,
> Sanjay
>

Angus Lees

unread,
Mar 3, 2011, 10:51:57 PM3/3/11
to andro...@googlegroups.com, krupa
dlopen works on android, as normal (almost):
- You need to specify the full library path, since LD_LIBRARY_PATH doesn't include your app directory (and that search path can't be changed once your process has started).
- Some of the usual Linux RTLD_* flags aren't supported.

I suggest you start by looking at any errors mentioned in logcat leading up to your failed dlopen() call.

 - Gus

krupa

unread,
Mar 3, 2011, 11:17:19 PM3/3/11
to android-ndk
I have specified the full library path , below is my sample
application code snippet accessing the library with dlopen -

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

typedef void (*simple_demo_function)(void);

int main(int argc, char **argv) {
void *handle;
char *error;


simple_demo_function demo_function;

handle = dlopen ("/u/equ_library_build/mp4040equ/tst/
mp4040equ_ARM_lib_test/libequ.so", RTLD_LAZY);

if (!handle) {

fputs (dlerror(), stderr);
exit(1);
}
printf("KKKKKK Calling dlsym\n");

demo_function = dlsym(handle, "MP4040EQU_Process");

if ((error = dlerror())) {
fprintf(stderr, "Couldn't find MP4040EQU_Process: %s\n", error);
exit(1);
}

/* Now call the function in the DL library */

(*demo_function)();

printf (">>>>> end of test >>>>>>");
dlclose(handle);
return 0;


}

Regards,
Krupa

On Mar 4, 8:51 am, Angus Lees <gusl...@gmail.com> wrote:
> dlopen works on android, as normal (almost):
> - You need to specify the full library path, since LD_LIBRARY_PATH doesn't
> include your app directory (and that search path can't be changed once your
> process has started).
> - Some of the usual Linux RTLD_* flags aren't supported.
>
> I suggest you start by looking at any errors mentioned in logcat leading up
> to your failed dlopen() call.
>
>  - Gus
>

Angus Lees

unread,
Mar 3, 2011, 11:46:26 PM3/3/11
to andro...@googlegroups.com, krupa
On Fri, Mar 4, 2011 at 15:17, krupa <gurura...@gmail.com> wrote:
       handle = dlopen ("/u/equ_library_build/mp4040equ/tst/
mp4040equ_ARM_lib_test/libequ.so", RTLD_LAZY);

This doesn't look like a regular Android app situation.  There could be all manner of complications here - and they are probably out of scope for the android-ndk mailing list.

You also didn't mention if there were any additional errors logged to the Android logs by the runtime linker.

 - Gus

krupa

unread,
Mar 4, 2011, 12:34:39 AM3/4/11
to android-ndk
I am not using Android NDK here, i am using linux commands to compile
the library .. I have built the library on linux and not on Android
NDK. i am using normal C program to access the library ..
On Mar 4, 9:46 am, Angus Lees <gusl...@gmail.com> wrote:

alan

unread,
Mar 4, 2011, 4:34:23 AM3/4/11
to andro...@googlegroups.com
code not compiled using the ndk will probably not run on android. using linux commands to compile the library will almost certainly fail. assuming you are using an arm compiler (although i suspect you are using an x86 compiler) then there may be a small chance of success but even then you wont be linking against android system libraries so it probably wont work.
you either need to use android.mk files or use the standalone toolchain provided with r5 of the ndk

krupa

unread,
Mar 4, 2011, 5:13:28 AM3/4/11
to android-ndk
I have already compiled the code and built the library on linux using
arm toolchain. My problem is i am not able to access the built library
( .so ) through a C code running on same linux. dlopen is throwing an
error saying cannot open the shared file ..

David Turner

unread,
Mar 4, 2011, 10:37:30 AM3/4/11
to andro...@googlegroups.com, krupa
The library you generated cannot run on Android. You need to use an Android-aware toolchain to do that.
Grab NDK r5b and read docs/STANDALONE-TOOLCHAIN.html to see how you could do that (without using a single Android.mk or ndk-build).

Reply all
Reply to author
Forward
0 new messages