Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to link with system library to vendor binary

Tags:

I am trying to access libsparese library in my binary which is present in vendor partition, but libsparse library is in system partition,During building it is throwing the below error.

(native:vendor) should not link to libsparse (native:platform)

How can I use that library, if it is present in system/lib64/?

like image 237
Rajeev Avatar asked Oct 05 '18 08:10

Rajeev


2 Answers

if your module is dependent on any system module then you can follow below steps to link your module to system module.

Example :- module A is a vendor platform module module B is a system platform module and you are getting below error after include the module B in your module A. module A (native:vendor) should not link to module B (native:platform) then.................. There is a work around for that..

Add module B absolute path in "LOCAL_C_INCLUDES+=" of module A make file. LOCAL_C_INCLUDES += \ /system//include

is the Module B is shared library then add below in module A make file. LOCAL_LDFLAGS += $(call intermediates-dir-for,SHARED_LIBRARIES,B)/B.so

At last add additional dependency for module B in module A LOCAL_ADDITIONAL_DEPENDENCIES := B

Now you can use module B in module A. :)

like image 139
Rajeev Avatar answered Sep 21 '22 05:09

Rajeev


You must not link against non-NDK platform libraries.

As see from https://android.googlesource.com/platform/bionic/+/372f19e9e27c1333c0fc1e83b53d365051e81612/android-changes-for-ndk-developers.md

Native libraries must use only public API, and must not link against non-NDK platform libraries. Starting with API 24 this rule is enforced and applications are no longer able to load non-NDK platform libraries. The rule is enforced by the dynamic linker, so non-public libraries are not accessible regardless of the way code tries to load them: System.loadLibrary, DT_NEEDED entries, and direct calls to dlopen(3) will all work exactly the same.

like image 40
shizhen Avatar answered Sep 21 '22 05:09

shizhen