1

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?

dspmihai
  • 21
  • 3

2 Answers2

0

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

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Unfortunately, the objdump -x and chrpath --list returned me no rpath. I have managed to build the library with soname and solved the problem, but now I have another library and no source code. It also has no rpath and I have the same problem – dspmihai Sep 12 '17 at 11:32
  • Are you sure you use the NDK version of objdump? Note that the *host* binary may show different results. Why does soname save the situation? – Alex Cohn Sep 12 '17 at 12:40
  • I have never tried this, but maybe the [patchelf](https://www.mankier.com/1/patchelf) utility can let you set SONAME for the prebuilt library, and then it will get loaded correctly. – Alex Cohn Sep 25 '17 at 11:52
0

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.

Sourav Dutta
  • 1,267
  • 1
  • 19
  • 25