GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cross Compile for Android and issues with PyExc_OSError · Issue #111225 · python/cpython

Cross Compile for Android and issues with PyExc_OSError #111225

New issue
Copy link
New issue
Copy link
Closed
#115780
Closed
Cross Compile for Android and issues with PyExc_OSError#111225
#115780
Copy link
Labels
OS-androidbuildThe build process and cross-buildThe build process and cross-buildtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@GRRedWings
GRRedWings
opened on Oct 23, 2023
Issue body actions

Bug report

Bug description:

In trying to run Python 3.12 on Android. I have been cross-compiling Python for a number of years. Having built a 64bit version I am getting the following error when I try to run

I get the following error at runtime.
ImportError('dlopen failed: cannot locate symbol "PyExc_OSError" referenced by "/data/data/com.myapp/files/Python64/lib-dynload/_socket.cpython-312.so"...')

I have verified that the _socket.cpython-3.12.so exists. I'm not really sure what other info would be beneficial for people to help me understand this error so I will start with this and happily add more details if requested.

CPython versions tested on:

3.12

Operating systems tested on:

Other

Linked PRs

  • gh-111225: Link extension modules against libpython on Android #115780

Activity

  1. GRRedWings
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 23, 2023
  2. AlexWaygood
    added
    buildThe build process and cross-buildThe build process and cross-build
    on Oct 24, 2023
  3. GRRedWings commented on Oct 27, 2023

    @GRRedWings
    GRRedWings
    on Oct 27, 2023
    Author
    More actions

    I'm not sure if this is useful, but I did find this in the Android NDK 26 notes

    Issue 360: thread_local variables with non-trivial destructors will cause segfaults if the containing library is dlcloseed. This was fixed in API 28, but code running on devices older than API 28 will need a workaround. The simplest fix is to stop calling dlclose. If you absolutely must continue calling dlclose, see the following table:

  4. mhsmith commented on Jan 16, 2024

    @mhsmith
    mhsmith
    on Jan 16, 2024
    Member
    More actions

    Issue 360: thread_local variables with non-trivial destructors will cause segfaults if the containing library is dlcloseed

    That doesn't seem relevant, because you're not seeing a segfault.

    More likely, _socket.cpython-3.12.so has not been linked against libpython3.12.so. You can check this using readelf -d.

  5. erlend-aasland commented on Jan 16, 2024

    @erlend-aasland
    erlend-aasland
    on Jan 16, 2024
    Contributor
    More actions

    @mhsmith, based on your comment, can we close this issue as not-planned?

  6. erlend-aasland
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Jan 16, 2024
  7. GRRedWings commented on Jan 18, 2024

    @GRRedWings
    GRRedWings
    on Jan 18, 2024
    Author
    More actions

    Here is the output I got from the readelf command. I'm not exactly sure how to read it, I do not see libpython3.12.so in there though, is this something I can change to link against it?

    image
  8. mhsmith commented on Jan 18, 2024

    @mhsmith
    mhsmith
    on Jan 18, 2024
    Member
    More actions

    I've just remembered, I also encountered this problem when building Python 3.12 for Chaquopy. I was able to fix it with this patch, which I'll turn into a pull request in the near future.

    Reacted by Brian Spratke
  9. erlend-aasland
    removed
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Jan 18, 2024
  10. GRRedWings commented on Jan 18, 2024

    @GRRedWings
    GRRedWings
    on Jan 18, 2024
    Author
    More actions

    @mhsmith - Thanks for the update. I have tried your patch as is. Something is still different because it's looking for python3.12.so instead of libpython3.12.so.

    I'm playing with your patch file, I'm not an expert but looking at it and trying to figure out what my build needs for some of your changes.

    /android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang -shared -L/python3-android/src/Python-3.12.1/Android/sysroot/usr/lib -pie Modules/arraymodule.o -lpython3.12 -o Modules/array.cpython-312.so
    clang-17: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
    ld.lld: error: unable to find library -lpython3.12

  11. mhsmith commented on Jan 19, 2024

    @mhsmith
    mhsmith
    on Jan 19, 2024
    Member
    More actions

    It doesn't say it's looking for python3.12.so, it says it's looking for -lpython3.12, which on Android, just like Linux, should be transformed into libpython3.12.so.

    The issue is probably that this file doesn't exist in any of the -L directories on your command line. In particular, I see that the command line doesn't contain -L., even though that should have been assigned to BLDLIBRARY here when ac_sys_system=Linux-android:

    cpython/configure

    Lines 7500 to 7502 in 2305ca5

    Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*|VxWorks*)
    LDLIBRARY='libpython$(LDVERSION).so'
    BLDLIBRARY='-L. -lpython$(LDVERSION)'

    Are you sure you applied the whole patch?

  12. GRRedWings commented on Jan 19, 2024

    @GRRedWings
    GRRedWings
    on Jan 19, 2024
    Author
    More actions

    I am pretty confident that I applied the entire patch. What I'm not sure is how I can tell if ac_sys_system is being set right. Is there a log or anything I could put into the configure? I tried using an echo and a printf, but not having any luck.

  13. GRRedWings commented on Jan 19, 2024

    @GRRedWings
    GRRedWings
    on Jan 19, 2024
    Author
    More actions

    In looking at this more, and doing a before and after, I can see that it is trying to apply the patch, I don't see errors, but the configure patch is not being applied. I will look into this and make sure the patch is being applied. Sorry about that.

  14. mhsmith commented on Jan 21, 2024

    @mhsmith
    mhsmith
    on Jan 21, 2024
    Member
    More actions

    I haven't looked at your build process, but maybe you're regenerating the configure script from the configure.ac file after applying the patch.

  15. GRRedWings commented on Jan 21, 2024

    @GRRedWings
    GRRedWings
    on Jan 21, 2024
    Author
    More actions

    You are correct. I didn't realize the script I was using was doing an auto reconfigure, and I was applying the patch before this. Once I applied the patch in the proper place, things worked as expected.

    I truly appreciate your help and time looking into this with me.

  16. GRRedWings
    closed this as completedon Jan 21, 2024
  17. mhsmith commented on Jan 21, 2024

    @mhsmith
    mhsmith
    on Jan 21, 2024
    Member
    More actions

    That's great, but please reopen the issue, because the original bug still exists in an unpatched version of Python.

  18. AlexWaygood
    reopened this on Jan 21, 2024
  19. encukou
    added this to Unsupported platformson Feb 1, 2024
  20. erlend-aasland
    added a commit that references this issue on Feb 21, 2024

    gh-111225: Link extension modules against libpython on Android (#115780)

    7f5e3f0
  21. erlend-aasland
    closed this as completedin #115780on Feb 21, 2024
  22. github-project-automation
    moved this to Done in Unsupported platformson Feb 21, 2024
  23. woodruffw
    added a commit that references this issue on Mar 4, 2024

    pythongh-111225: Link extension modules against libpython on Android (p…

    90ac592
  24. encukou
    added
    OS-android
    on Mar 20, 2024
  25. encukou
    removed this from Unsupported platformson Mar 20, 2024
  26. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-111225: Link extension modules against libpython on Android (p…

    1bd2625
  27. GRRedWings commented on Jul 9, 2024

    @GRRedWings
    GRRedWings
    on Jul 9, 2024
    Author
    More actions

    It's been a while, trying to build against 3.12.4, is this patch still needed?

  28. mhsmith commented on Jul 9, 2024

    @mhsmith
    mhsmith
    on Jul 9, 2024
    Member
    More actions

    It's still needed on Python 3.12 and older, but it won't be needed in Python 3.13.

  29. GRRedWings commented on Jul 9, 2024

    @GRRedWings
    GRRedWings
    on Jul 9, 2024
    Author
    More actions

    Perfect, I figured as much but wanted to be sure. I appreciate it.

  30. LukasWoodtli
    added a commit that references this issue on Jan 22, 2025

    pythongh-111225: Link extension modules against libpython on Android (p…

    b86840b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-androidbuildThe build process and cross-buildThe build process and cross-buildtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.