Android NDK shared libraries

久未见 提交于 2019-12-11 04:13:54

问题


I am trying to build a native library for an Android application. I have 2 libraries and I need to link them in my final library, but I have some problems. The Android.mk code:

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. The ndk-depends output:

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. Does somebody know what might be?


回答1:


The libfn_dsp.so binary was - for whatever reason - built with rpath without SONAME. You can use objdump utility (bundled in Android NDK) to see the proof.

If you cannot rebuild this library, follow the discussion here: Can I change 'rpath' in an already compiled binary?.




回答2:


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

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. 2. Otherwise, you use System.loadLibrary("fn_dsp") manually load libfn_dsp.so before loading libprocess.so.



来源:https://stackoverflow.com/questions/46172216/android-ndk-shared-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!