4

first of all I want to tell you what I want to do. I have a .h-file and a .c-file with usual C-Code in it with which I created a shared library with the Android NDK. So now I have a .so-file which is called libtry.so. Furthermore, I want to use native code in my Android Eclipse project. So I created .java-file with the class "Counter" and the content

public native static int Number(int n);

and

static
{
   System.loadLibrary("test");
}

Then I create a C-header file from the .java-file with the javah tool.

Afterwards I create a C-sourcefile for the C-Headerfile in which I implement the native code.

Then I create a shared library with those two files with LOCAL_MODULE := test, so that the file will be named libtest.so . But the point is, that I want to link the shared library libtry.so, which I created at the beginning, to this shared library.

So in the Android.mk-file of libtest.so I put LOCAL_LDLIBS := -L/root/Android/Samples/Test/libs/ -ltry .

Actually this works because I can compile this Android.mk-file with ndk-build.

But now in my Eclipse project, if I want to use the library libtest.so it does not work. I mean If I create an object of the Class "Counter" in which the library libtest.so is loaded,

I get the error: "Cannot load library: link_image[1966]: 1752 could not load needed library 'libtry.so' for 'libtest.so'" .

What am I doing wrong? Thanks in advance.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
Eddy Gordo
  • 61
  • 1
  • 7
  • are you using your so file for a different project or the one in which you have your C code – Sunny Kumar Aditya Jun 27 '12 at 10:47
  • For the same project. Actually I want to explain it again for some more details. The .so file libtry.so contains functions which have to be used by libtest.so. So what I did was to link the libtry.so to libtest.so in the Android.mk of libtest.so, like shown in my first comment. I can compile with the ndk-buid. But I cannot use the libtest.so in my Eclipse proejct because of the error shown in the title of this topic. – Eddy Gordo Jun 27 '12 at 11:21
  • My answer with this link was deleted. http://stackoverflow.com/questions/10593987/android-ndk-linking/10615769#10615769 In response to your reply, yes, the steps in the link shows how to build a 3rd libtry.so with just c source. In my case it was a physics library which we have to use in many of our games. So we considered building a separate lib for future use. – codetiger Jun 28 '12 at 04:28
  • Thank you codetiger for your link. I will give it a try and tell you how it worked. – Eddy Gordo Jun 28 '12 at 06:59
  • Did you solve this problem ? i'm getting the same error – Jerec TheSith Nov 26 '12 at 11:32

1 Answers1

4

You are linking a library to a library. In the Java code they must be loaded explicitly in reverse order e.g.

static
    {
        System.loadLibrary("dependencylib"); // try 
        System.loadLibrary("mainlib");       // test
    }

Answer taken from here

Community
  • 1
  • 1
tmanthey
  • 4,547
  • 6
  • 35
  • 42