shared so library problem

33 views
Skip to first unread message

EricS

unread,
Mar 31, 2010, 8:41:53 AM3/31/10
to android-ndk
Hi,

I am new to android development. We have many c++ libraries that we
would like to use on Android.

I am made an interface shared libary that I am able to run in a java
app, but when I attempt to link another so library, the first so
library fails to load.

Here is my andriod.mk file for the java jni so file:

# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := XInterface
LOCAL_SRC_FILES := ../src/XInterface.cpp
LOCAL_CPPFLAGS += -D ANDROID
LOCAL_C_INCLUDES :=$(LOCAL_PATH)/../../
LOCAL_SHARED_LIBRARIES := XCalcs

include $(BUILD_SHARED_LIBRARY)

Here is my linked in so library android.mk file for the XCalcs so
library:

# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := XCalcs
LOCAL_SRC_FILES := ../src/Location.cpp
LOCAL_CPPFLAGS += -D ANDROID
LOCAL_C_INCLUDES :=$(LOCAL_PATH)/../../
include $(BUILD_SHARED_LIBRARY)

I am using ndk r3 and google version 2.1 of the sdk. What
modifications do I need to make to get these so libaries to load on
the android?

Thanks

Eric

David Turner

unread,
Mar 31, 2010, 1:50:13 PM3/31/10
to andro...@googlegroups.com
What is the error message when trying to load the dynamic library ?
The logcat output should give you information about what is wrong here.


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


EricS

unread,
Apr 1, 2010, 8:09:04 AM4/1/10
to android-ndk
In the logcat window of Eclipse it says it can not find XCalcs module
(library). My problem is that I have checked and both libraries are
in the Emulator in the same folder/directory. Also XCalcs does not
have any dependencies.

How can I work around this issue?

Another question, is there a limit on the size of a so file?

Thanks

Eric

> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr­oups.com>


> > .
> > For more options, visit this group at

> >http://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

mic _

unread,
Apr 1, 2010, 8:29:22 AM4/1/10
to andro...@googlegroups.com
It will be easier for people to spot the problem if you posted the
exact logcat output.

/Michael

> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

EricS

unread,
Apr 1, 2010, 11:59:03 AM4/1/10
to android-ndk
Here is what logcat says:

04-01 15:52:21.333: DEBUG/dalvikvm(237): Trying to load lib /data/data/
com.staudertech/lib/libXInterface.so 0x43d02d68
04-01 15:52:21.364: INFO/dalvikvm(237): Unable to dlopen(/data/data/
com.staudertech/lib/libXInterface.so): Cannot load library:
link_image[1721]: 29 could not load needed library 'libXCalcs.so'
for 'libXInterface.so' (load_library[1051]: Library 'libXCalcs.so' not
found)
04-01 15:52:21.373: WARN/dalvikvm(237): Exception Ljava/lang/
UnsatisfiedLinkError; thrown during Lcom/staudertech/
StauderInterface;.<clinit>

Both the so libraries are in the same location.

Thanks

Eric

> >> >http://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -


>
> >> - Show quoted text -
>
> > --
> > 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 athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -

EricS

unread,
Apr 5, 2010, 1:17:11 PM4/5/10
to android-ndk
Is there any suggestions on how to solve this issue? Can I compile /
link it a different way to get around this issue?

If so how?

Any suggestions would be appreciated.

Thanks

Eric

> > >> >http://groups.google.com/group/android-ndk?hl=en.-Hidequoted text -


>
> > >> - Show quoted text -
>
> > > --
> > > 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 athttp://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

David Turner

unread,
Apr 5, 2010, 2:21:41 PM4/5/10
to andro...@googlegroups.com
On which version of the system are you running this ? The Android 1.5 dynamic linker had a bug that looks like exactly your bug. This was fixed in 1.6.

EricS

unread,
Apr 5, 2010, 4:13:24 PM4/5/10
to android-ndk
I am running this on the emulator on the March 2010 NDK r3. The
selected platform is 2.1 with the eclipse adt of 0.9.6.

Thanks

Eric

> > groups.google.com/group/android-ndk?hl=en.-Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> > 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<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > .
> > For more options, visit this group at

> >http://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -

David Turner

unread,
Apr 5, 2010, 4:19:18 PM4/5/10
to andro...@googlegroups.com
this is strange, what is the exact output of the following:

adb shell ls /data/data/com.staudertech/lib

?

To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

EricS

unread,
Apr 6, 2010, 8:07:17 AM4/6/10
to android-ndk
The output is:

C:\>adb shell ls /data/data/com.staudertech/lib
libXCalcs.so
libXInterface.so

Thanks

Eric

> > > >http://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -

David Turner

unread,
Apr 6, 2010, 2:40:59 PM4/6/10
to andro...@googlegroups.com
ah sorry, what about using the -l flag too to see permissions and library sizes, i.e.

adb shell ls -l /data/data/com.staudertech/lib

To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

EricS

unread,
Apr 7, 2010, 8:10:11 AM4/7/10
to android-ndk
Here is the output:


C:\>adb shell ls -l /data/data/com.staudertech/lib
-rw-r--r-- system system 72826 2010-04-01 10:46 libXCalcs.so
-rw-r--r-- system system 298112 2010-04-01 10:47
libXInterface.so

C:\>

Is there a size limit on the so files? Should I be doing this linking
another way?

Thanks

Eric

> > > > > >http://groups.google.com/group/android-ndk?hl=en.-Hidequoted text


> > -
>
> > > > > - Show quoted text -
>
> > > > --
> > > > 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<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > <android-ndk%2Bunsubscribe@googlegr­oups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> > 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
>

> ...
>
> read more »- Hide quoted text -

Addy

unread,
Apr 8, 2010, 8:44:14 AM4/8/10
to android-ndk

Hi Erics,

Before some day I had a same problem of dlopen() cant open .so file at
the runtime.

I think,

U just put the libXCalcs.so file in your ndk root android-ndk-r3/build/
platforms/android-5<whatever you use 3-4-5>/arch-arm/usr/lib folder
and try it.

May be It works..

> ...
>
> read more »

EricS

unread,
Apr 8, 2010, 10:44:26 AM4/8/10
to android-ndk
I finally got this to work, but adding another
system.loadLibrary("XCalcs"); before the
system.loadLibrary("XInterface"); statement.

Evidently, if you have so files that depend on each other, you have to
add the loadLibary statement for each dependency.

Thanks for your assistance.

Thanks

Eric

> ...
>
> read more »- Hide quoted text -

Addy

unread,
Apr 16, 2010, 2:01:35 AM4/16/10
to android-ndk
Hi Erics.

I read your questions.

And I tried with your suggestion,

I work on chm application in which I want to load dynamically linked
library libchm.so.

And In my java file I put the same code..

system.loadLibrary("chm");
system.loadLibrary("test_demo");

and then compile it at the ndk_root directory with

make APP=test_demo command,

but it gives error

Android NDK: Building for application 'test_demo'
Compile thumb : test_demo <= ~/workspace/test_demo/jni/test_demo.c
make: *** No rule to make target `out/apps/test_demo/armeabi/
libchm.so', needed by `out/apps/test_demo/armeabi/libtest_demo.so'.
Stop.

in test_demo.c I used some functions which are dependent on libchm.so
file.

can you please help me?
> ...
>
> read more »

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

EricS

unread,
Apr 16, 2010, 7:49:12 AM4/16/10
to android-ndk
Hi Andy,

Yes, I did not document what I did when I link the shared libraries
together. Copy the shared so to the out directory of test_demo, then
it should find it and link.

Thanks

Eric
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages