Re: how to consume shared object from /system/lib

37 views
Skip to first unread message

David Turner

unread,
May 18, 2013, 5:00:27 AM5/18/13
to andro...@googlegroups.com



On Fri, May 17, 2013 at 5:19 PM, June Ree <stepbyste...@gmail.com> wrote:
Hello,

I have libtestserver.so in /system/lib in my phone.

I need to use this shared library in my project so...something like...

#include "libtestserver_header.h"

here is libjnitest.c

.....jint Java_blah_blah...(...)
    .......//in this method..I called a function from libtestserver
          libtestserver_functionA();
}

Here is my Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_LDLIBS := -ltestserver
LOCAL_MODULE    := libjnitest
LOCAL_SRC_FILES := libjnitest.c

include $(BUILD_SHARED_LIBRARY)

from ndk-build, it complains about "ld: error :cannot find -ltestserver"...
Well..it kinda makes sense....I have that libtestserver.so in the phone, but in my development env, I don't have it..


I confirm that it is correct to use LOCAL_LDLIBS to reference system libraries with -l<name>
This also ensure that the library is not copied into your project's libs/$ABI/ directory during the build.

Also, you are correct about the error above, the linker complains because it cannot find the library on the host development machine.
 
So...

I changed the Android.mk like this to include that shared object file like..

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := testserver
LOCAL_SRC_FILES := $(LOCAL_PATH)/../libs/libtestserver.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

include $(PREBUILT_SHARED_LIBRARY)

Note that this will copy your libtestserver.so into the project's libs/$ABI/ directory, and this copy will end up inside your application's APK. This is probably not what you want to do. If all you want is reference an existing system library, your options are:

1/ Simply copy the library to platforms/android-<n>/arch-<arch>/usr/lib, the use LOCAL_LDLIBS += -l<name>
2/ Hard-code the path to the library instead:  LOCAL_LDLIBS += /path/to/lib<name>.so
 
include $(CLEAR_VARS)

LOCAL_LDLIBS := -L$(LOCAL_PATH)/../libs/armeabi -ltestserver
LOCAL_MODULE    := libjnitest
LOCAL_SRC_FILES := libjnitest.c

include $(BUILD_SHARED_LIBRARY)

No "ld cannot find error" any more but...still got an error "undefined reference to libtestserver_functionA()"...

Your code is looking for a C++ function called "libtestserver_functionAt()", are you sure libtestserver.so doesn't export the symbol as a C function instead ?
 
Here is some error message..

Install        : libtestserver.so => libs/armeabi/libtestserver.so
BFD: ...../libs/armeabi/sthU0Jm9: warning: sh_link not set for section `.ARM.exidx'
...
SharedLibrary  : libjnitest.so
....................
.........................error: undefined reference to 'libtestserver_functionA()'
collect2: ld returned 1 exit status

Any idea?
Thanks,

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages