Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

dynamic library does not have SONAME #36

Open
GRRedWings opened this issue Sep 3, 2020 · 7 comments
Open

dynamic library does not have SONAME #36

GRRedWings opened this issue Sep 3, 2020 · 7 comments
Labels

Comments

@GRRedWings
Copy link

In trying to figure out issues I'm having on older devices running 6.0.1, I'm wondering if some of my issues are that I had to change how I import the library. In looking back at my fork, the dynamic library has an SONAME, the current version coming from this fork are not. In looking back at Issue 18 I noticed that my errors was showing the windows style path, and I wonder if it's causing some of my issues. As described here

On a side note, I also see that Python 3.9b5 is available. I tried adding a similar path to the configure.ac, but I didn't have much luck.

@yan12125
Copy link
Owner

yan12125 commented Sep 4, 2020

Adding SONAME requires some non-trivial patches to setup.py and/or distutils. I'd like a self-contained App to test before investing time into SONAME stuffs.

Also, I really suggest you to build static library libpython.a and link your JNI library to libpython.a so to get rid of all the issues around dynamic linking.

@GRRedWings
Copy link
Author

I played around and added the following patch to configure.ac. I realize this is hard coded, but this added the SONAME to my dynamic library, and fixed some of my issues.

`diff --git a/configure.ac b/configure.ac
index 73ee71c6d2..a62edaebae 100644
--- a/configure.ac 2020-09-03 13:02:27.847717033 -0700
+++ b/configure.ac 2020-09-03 13:14:11.101958236 -0700
@@ -890,8 +890,9 @@
AC_SUBST(MULTIARCH_CPPFLAGS)

AC_MSG_CHECKING([for -Wl,--no-as-needed])
+LDFLAGS="$LDFLAGS -Wl,-soname,libpython3.9.so"
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[NO_AS_NEEDED="-Wl,--no-as-needed"
AC_MSG_RESULT([yes])],

`

@GRRedWings
Copy link
Author

I have tried to get the static library to work, but I have not had much luck. Any chance you can point me in the right direction if you recommend that, or update my test app to show how that would work?

@yan12125
Copy link
Owner

Sorry, but I don't have much time recently for testing it. Mind to share error messages you've got? (I'm not asking for a complete example this time - I know preparing it is very time consuming :P)

I think after rebuilding python3-android as static libraries and remove loadLibrary("python3.9") are first steps?

@GRRedWings
Copy link
Author

I feel I'm doing something wrong. I've tried adding these lines to CMakeLists

find_library(LIB_TO_INCLUDE ClassLibrary ${distribution_dir}/jnilibs/${ANDROID_ABI})
target_link_libraries(python39 ${LIB_TO_INCLUDE})

but get this error

CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "python39" which is not built by
this project.

I've tried to just change what is currently in the CMakesList.txt and use STATIC instead of SHARED and .a instead of .o. The app then compiles, but crashes at runtime with
CMakeLists

add_library(python39 STATIC IMPORTED)
set_target_properties(python39 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpython3.9.a)

Runtime Output

2020-09-17 10:23:49.568 29855-29855/com.example.pythontest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pythontest, PID: 29855
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libpython3.9.so" not found

At this point I feel I need to create a fork of your project that has my hack in configure.ac so I can at least get back to that if needed. Maybe we can get a static build working, but other then a requests library input failing on my 32 bit 6.0.1 device, everything works with this SONAME patch.

@GRRedWings
Copy link
Author

GRRedWings commented Sep 17, 2020

As an added note. I'm pretty much giving up on the 1 device that doesn't run this. I tracked it down to the requests library (https://requests.readthedocs.io/en/master/) It appears to fail in urllib3 when trying to make the following import

from __future__ import absolute_import

I tried removing these imports, but it only created other issues. Just sharing for the sake of sharing, not sure it helps anyone understand my issues.

@yan12125
Copy link
Owner

java.lang.UnsatisfiedLinkError: dlopen failed: library "libpython3.9.so" not found

Hmm, that's strange. If you want to continue the state library approach, could you check if readelf -d libpythonthread.so still has libpython3.9.so (it shouldn't now), and the System.loadLibrary("python3.9"); has been removed from Java files?

It appears to fail in urllib3 when trying to make the following import

Yet another strange stuff... absolute_import is enabled by default on Python 3.x.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants