Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can shared library call another shared library?

Tags:

android

shared

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.

like image 329
Viktor Apoyan Avatar asked May 18 '11 08:05

Viktor Apoyan


1 Answers

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);
    }
} 
like image 173
Vladimir Berezkin Avatar answered Oct 22 '22 20:10

Vladimir Berezkin