可以共享库加载并调用函数从另一共享库?
我的共享库的 libDsmTestLib.so 使用另一个共享库 libDsmShared.so 和 libPINDsmShared.so
LOCAL_PATH:= $(叫我-DIR)
包括$(CLEAR_VARS)
LOCAL_MODULE:= DsmTestLib
LOCAL_SRC_FILES:= DSM_Library.cpp
LOCAL_LDLIBS:= -lDsmShared
LOCAL_LDLIBS + = -lPINDsmShared
包括$(BUILD_SHARED_LIBRARY)
当我创建的 libDsmTestLib.so 并想用它在我的Android的Java应用程序是这样的:
包com.dsm;
进口android.app.Activity;
进口android.os.Bundle;
公共类dsmTest延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
}
静态{
尝试 {
的System.loadLibrary(DsmTestLib);
}
赶上(的UnsatisfiedLinkError E){
通信System.err.println(乡土code库加载失败\ñ。+ E);
}
}
}
在catch块我得到错误
无法加载库:link_image [1962]: 33无法加载所需的库 libDsmShared.so为 libDsmTestLib.so (load_library [1104]:图书馆 libDsmShared.so未找到)
LoadLibrary函数不能发现库的 libDsmShared.so 使用我的主库 libDsmTestLib.so ,谁能知道为什么?而我能做些什么来解决这个问题呢?
我有一个静态库(。所以用C ++编写)与功能,我想从我的Java的Android应用程序的使用,为我创造,我调用该函数从previously的.cpp和.h文件创建的库。
解决方案Android的动态链接器有这样的起价工作pvented这名P $的错误, 但 固定在1.6,我相信。 如果你使用NDK,用LOCAL_SHARED_LIBRARIES:= libB的libC时, 定义 在力霸模块。 这假定libB或是libc是生成的还NDK模块 与NDK。
如果libB.so和libC.so不与NDK生成的,你应该做的
下列:
在力霸模块定义,使用LOCAL_LDLIBS + = /full/path/to/libB.so /full/path/to/libC.so 这确保了在libA.so产生正确的符号出口
手动复制libB.so和libC.so至$ APP_PROJECT /库/ armeabi 之前 重建你的apk文件, 这保证了它会被复制到/数据/数据// lib中的 由包管理器的安装时间。
LOCAL_PATH:= $(叫我-DIR)
包括$(CLEAR_VARS)
LOCAL_MODULE:= DsmTestLib
LOCAL_SRC_FILES:= DSM_Library.cpp
#LOCAL_SHARED_LIBRARIES:= DsmShared
#LOCAL_SHARED_LIBRARIES + = PINDsmShared
#设置本地库完整路径。
LOCAL_LDLIBS:= C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so
LOCAL_LDLIBS + = C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libPINDsmShared.so
包括$(BUILD_SHARED_LIBRARY)
无法加载库:link_image [1962]: 33无法加载所需的库 C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so 对于libDsmTestLib.so (load_library [1104]:图书馆 C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so 未找到)
发生,但是当我检查C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so这条道路,我发现库的存在有......有什么梅特
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 ?
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.
解决方案The Android dynamic linker had a bug that prevented this from working, but was fixed in 1.6, I believe. If you use the NDK, use "LOCAL_SHARED_LIBRARIES := libB libC" when defining the libA module. This assumes that libB and libC are also NDK modules that were generated with the NDK.
In case libB.so and libC.so are not generated with the NDK, you should do
the following:
in the libA module definition, use LOCAL_LDLIBS += /full/path/to/libB.so /full/path/to/libC.so this ensures that correct symbol exports are generated in libA.so
manually copy libB.so and libC.so to $APP_PROJECT/libs/armeabi before rebuilding your .apk, this ensures that it will be copied to /data/data//lib at installation time by the package manager.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := DsmTestLib
LOCAL_SRC_FILES := DSM_Library.cpp
#LOCAL_SHARED_LIBRARIES := DsmShared
#LOCAL_SHARED_LIBRARIES += PINDsmShared
# Set local libs with full path.
LOCAL_LDLIBS := C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so
LOCAL_LDLIBS += C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libPINDsmShared.so
include $(BUILD_SHARED_LIBRARY)
Cannot load library: link_image[1962]: 33 could not load needed library 'C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so' for 'libDsmTestLib.so' (load_library[1104]: Library 'C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so' not found)
occurred, but when I check C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so this path I found that the library exists there ... What's the metter ?