Prebuilt library path hardcoded into executable in Android.O using Android.bp

1,492 views
Skip to first unread message

Vijay Ch

unread,
Feb 25, 2018, 2:05:28 PM2/25/18
to Android Building
I have a prebuilt library libmyLibrary.so which is linked against Myexecutable as below.
My Android.bp file is as below.

//Prebuilt library
cc_prebuilt_library_shared {
    name: "libmyLibrary",
   relative_install_path: "hw",,
    proprietary: true,

   target: {   
     android_x86_64: {

        srcs: [

        "./target64/libmyLibrary.so",    //path of prebuilt library
     ],
    },
   android_x86: {
 
    srcs: [
        "./target32/libmyLibrary.so",  
//path of prebuilt library
     ],
    },
   },
   strip: {
      none: true,
    },
}


Note: The libmyLibrary.so is available in the path /AOSP/vendor/xxx/yyy/target64/libmyLibrary.so

//Binary links against libMyLibarry.so

c_library_shared {
    name: "Myexecutable",
    vendor: true,
    relative_install_path: "hw",
    
   strip: {
      none: true,
    },
  srcs: [
        "Main.cpp",
     ],
    shared_libs: [
        "libmyLibrary",
        ]
}

Now the build is successful without any errors.
after successfull flashing of the image, my binary is copied into /vendor/bin/hw and library is copied into /vendor/lib64/hw.

When i try to execute the binary i got the below error.

CANNOT LINK EXECUTABLE "Myexecutable ": library " vendor/xxx/yyy/target64/libmyLibrary.so" not found


That means it is looking for the absolute path of the library instead of relative path.

When i open the binary in textformat, it is referring to the absolute path (where i copied the lib in Build PC).

I guess it require some ldflag or cflag to be set.
Could someone please tell me how to set the flags or solution to the above problem?

Thanks in Advance,
Vijay




Vijay Ch

unread,
Feb 26, 2018, 10:10:37 AM2/26/18
to Android Building
I tried by setting different ldflags, but couldn't get the solution.
Android experts kindlhy give your suggestions.

Thanks in Advance
Vijay

Vasishath Kaushal

unread,
Feb 26, 2018, 2:52:26 PM2/26/18
to Android Building
I dont know if this relates to ur case but i have faced a similar problem with cmake in the past. This is a general behaviour of make in which the binaries generated in build tree will always have hardcoded absolute paths to shared libraries. But if one runs make install and then uses those binaries, they have relative paths.
The binaries generated by make install are the ones meant to be finally used and run on the target system.

Did u also copy the binaries from an intermediate directory ?

Hope this helps.

Dan Willemsen

unread,
Feb 26, 2018, 2:56:31 PM2/26/18
to Android Building
I'm not sure, but I suspect your SONAME is incorrect in your shared library. Make sure that you've specified -Wl,-soname,libmyLibrary.so (or equivalent) when building your library.

- Dan


--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-building@googlegroups.com
To unsubscribe from this group, send email to
android-building+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-building+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Ch

unread,
Feb 27, 2018, 10:22:16 AM2/27/18
to Android Building
Hello Dan,
you are right, the prebuilt library is missing SONAME.
After building the library with -Wl,-soname,libmyLibrary.so option, it works fine.
Thank you very much.


On Tuesday, 27 February 2018 01:26:31 UTC+5:30, Dan Willemsen wrote:
I'm not sure, but I suspect your SONAME is incorrect in your shared library. Make sure that you've specified -Wl,-soname,libmyLibrary.so (or equivalent) when building your library.

- Dan
On Mon, Feb 26, 2018 at 10:50 AM, Vasishath Kaushal <vasi...@gmail.com> wrote:
I dont know if this relates to ur case but i have faced a similar problem with cmake in the past. This is a general behaviour of make in which the binaries generated in build tree will always have hardcoded absolute paths to shared libraries. But if one runs make install and then uses those binaries, they have relative paths.
The binaries generated by make install are the ones meant to be finally used and run on the target system.

Did u also copy the binaries from an intermediate directory ?

Hope this helps.

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.

Vijay Ch

unread,
Feb 27, 2018, 10:22:16 AM2/27/18
to Android Building
I think i don't have option to install using Cmake.
Because The library is provide by third party which was built using Android NDK.
And i am trying to integrate in my module in Android source code.
Finally i am making the image and flashing to the target.
Reply all
Reply to author
Forward
0 new messages