Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

android - Can shared library call another shared library?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.
" + e);
    }
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...