[英]Android NDK shared libraries
I am trying to build a native library for an Android application. 我正在尝试为Android应用程序构建本机库。 I have 2 libraries and I need to link them in my final library, but I have some problems. 我有2个库,需要将它们链接到我的最终库中,但是有一些问题。 The Android.mk code: Android.mk代码:
LOCAL_CFLAGS := -Wall -Wfloat-equal -std=c99
LOCAL_PATH := $(call my-dir)/..
include $(CLEAR_VARS)
LOCAL_MODULE := cpu-lib
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/cpu/inc
LOCAL_EXPORT_CPPFLAGS := $(LOCAL_CFLAGS)
LOCAL_EXPORT_LDLIBS := -llog
LOCAL_SRC_FILES := $(LOCAL_PATH)/cpu/lib/$(TARGET_ARCH_ABI)/libdemoDSP.so
LOCAL_STATIC_LIBRARIES := gnustl_static
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dsp-lib
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/dsp/inc
LOCAL_EXPORT_CPPFLAGS := $(LOCAL_CFLAGS)
LOCAL_EXPORT_LDLIBS := -llog
LOCAL_SRC_FILES := $(LOCAL_PATH)/dsp/lib/$(TARGET_ARCH_ABI)/libfn_dsp.so
LOCAL_STATIC_LIBRARIES := gnustl_static
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := process
LOCAL_SRC_FILES := process.cpp
LOCAL_SHARED_LIBRARIES := cpu-lib dsp-lib
include $(BUILD_SHARED_LIBRARY)
The problem is that the dlopen won't find the libfn_dsp.so. 问题是dlopen找不到libfn_dsp.so。 The ndk-depends output: ndk依赖输出:
ndk-depends libs\arm64-v8a\libprocess.so
WARNING: Could not find library: ./obj/local/arm64-v8a/libfn_dsp.so
libprocess.so
liblog.so
libdemoDSP.so
libstdc++.so
libm.so
libdl.so
libc.so
./obj/local/arm64-v8a/libfn_dsp.so
It seems that is something strange with that lib. 那个lib似乎有些奇怪。 Does somebody know what might be? 有人知道会是什么吗?
The libfn_dsp.so binary was - for whatever reason - built with rpath without SONAME. 出于某种原因, libfn_dsp.so二进制文件是使用不带SONAME的rpath构建的。 You can use objdump utility (bundled in Android NDK) to see the proof. 您可以使用objdump实用程序(捆绑在Android NDK中)查看证明。
If you cannot rebuild this library, follow the discussion here: Can I change 'rpath' in an already compiled binary? 如果您无法重建该库,请遵循此处的讨论: 我可以在已编译的二进制文件中更改“ rpath”吗? . 。
The problem is libfn_dsp.so miss SONAME info
, you can use " readelf --dynamic libfn_dsp.so |grep SONAME
" then check output info is empty, And you can use " readelf --dynamic libdemoDSP.so |grep SONAME
", which output info is " libdemoDSP.so
". 问题是libfn_dsp.so miss SONAME info
,您可以使用“ readelf --dynamic libfn_dsp.so |grep SONAME
”,然后检查输出信息是否为空,而您可以使用“ readelf --dynamic libdemoDSP.so |grep SONAME
”,这输出信息为“ libdemoDSP.so
”。
how to fix: 1. If you have libfn_dsp.so
source code, you can compile it with newest NDK, or with older NDK add " -Wl,-soname,libfn_dsp.so
" option. 如何解决:1.如果您具有libfn_dsp.so
源代码,则可以使用最新的NDK进行编译,也可以使用较旧的NDK对其进行添加“ -Wl,-soname,libfn_dsp.so
”选项。 2. Otherwise, you use System.loadLibrary("fn_dsp")
manually load libfn_dsp.so
before loading libprocess.so
. 2.否则,您使用System.loadLibrary("fn_dsp")
手动加载libfn_dsp.so
加载之前libprocess.so
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.