Can shared library call another shared library?

Viktor Apoyan picture Viktor Apoyan · May 18, 2011 · Viewed 19.2k times · Source

Can one shared library load and call functions from another shared library?

I have Shared library libDsmTestLib.so that use another shared libraries libDsmShared.so and libPINDsmShared.so

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE           := DsmTestLib
LOCAL_SRC_FILES        := DSM_Library.cpp

LOCAL_LDLIBS := -lDsmShared
LOCAL_LDLIBS += -lPINDsmShared

include $(BUILD_SHARED_LIBRARY)

when I create libDsmTestLib.so and want to use it in my android java application like this:

package com.dsm;

import android.app.Activity;
import android.os.Bundle;

public class dsmTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
      
    static {
        try {
            System.loadLibrary("DsmTestLib");
        }
        catch( UnsatisfiedLinkError e ) {
             System.err.println("Native code library failed to load.\n" + e);
        }
    }  
}

In the catch block I get error

Cannot load library: link_image[1962]: 33 could not load needed library 'libDsmShared.so' for 'libDsmTestLib.so' (load_library[1104]: Library 'libDsmShared.so' not found)

Loadlibrary function cant find library libDsmShared.so that uses my main library libDsmTestLib.so, Who can tell why ? and what can I do to solve this problem ?


Additional Information

I had a static library (.so written in C++) with functionality which I want to use from my Java android application, for that I create .cpp and .h files in which I call the function from the previously created library.

Answer

Vladimir Berezkin picture Vladimir Berezkin · Sep 14, 2011

I found solution in this way - explicity loading libraries:

    static {
    try {
        System.loadLibrary("DsmShared");
        System.loadLibrary("DsmTestLib");
    }
    catch( UnsatisfiedLinkError e ) {
         System.err.println("Native code library failed to load.\n" + e);
    }
}