-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python-for-android: ImportError: Cannot locate symbol #129
Comments
your output doesn't look too different from mine (a x86_64 build). I guess since you're referencing it, is Py_ENABLE_SHARED false?
assuming it is true, next thing to naively wonder is what is the output of ldd
emphasis on the presence of libpython if it's there, you'll have reached the limits of my expertise on the subject. |
For future reference, the python code that worked for me is
Which, yes, returns true (1). And ld is not linking against libpython, so maybe I should add a new linker flag to take care of that. |
After linking against libpython, the error has changed to: Which is the kind of issue you'd run into when cross-compiling with earlier versions of ldc. In recent versions of ldc, it all just works. You can cross-compile a D program and run it from the Android adb terminal. So I believe this is related to ldc2 not passing the right target to clang unless specified, which is happening in my build environment (python-for-android / distutils). This line in ldc2.conf should not be necessary to begin with:
@ariovistus do you know if distutils might be setting some environment compiler/linker flags on its own? Something that explains ldc misbehaving, or that overrides llvm/clang configuration? |
if memory serves, everything distutils gives a compiler is either an argument to DCompiler.compile or DCompiler.link, or something passed along by DCompiler. shouldn't be too difficult to slip a verbose flag in there if you want to see what ldc is actually passing to the linker |
I've solved the clang issue, and ldc now builds and links without problems. But it turns out that the tls issue is due to unfulfilled requirements specific to Android binaries: https://wiki.dlang.org/Build_D_for_Android#Changes_for_Android
About 2), I think I'm going to have to patch pyd to comment out the What are your thoughts @ariovistus ? Also from the wiki:
How does this fall in place with Python importing and running pyd objects? Is this what |
been a while since I've messed with d disassembly, but isn't _Dmain the D main function they're referencing? well, maybe not, maybe the compiler injects some extra smarts in when it sees "void main()" or its ilk. it looks like if d_lump=False you will need to ensure the linking order is satisfied in dcompiler.py, otherwise there's only one object file. python_so_linux_boilerplate.d does deal with calling rt_init and rt_term. looks like when gcc is available it uses some gcc attributes in so_ctor.c, when LDC is available it uses some LDC specific pragmas. don't think you need to do anything here. |
I have cross-compiled, linked and installed a pyd module (which consists of only one exported class) under python-for-android. The goal is to run a kivy GUI frontend to the app's D language backend on Android platforms. (Since ldc now supports ARM targets.)
So I wrote a simple hello world
main.py
:Here's worldwrapper.d:
Here's the ordinary setup.py (building deimos):
Long story short: I got python-for-android to patch pyd so it passes ldc2 the target parameter
-mtriple=armv7a--linux-androideabi
. Then it runspython3 setup.py install
which cross-compiles and installs the shared library under python-for-android's site-packages.Here's python-for-android running our patched distutils:
This is all brilliantly accomplished by extending
etc/ldc2.conf
with this target configuration:Notice it's using ldc's prebuilt arm eabi runtime libraries (installed under
/lib-armv7a-32
) which allow running D code on Android.The result is a cross-compiled worldwrapper.so:
But I believe I'm running into linking issues, because python crashes with the following error on line 6 in main.py (extract from the Android phone's logcat):
ImportError: dlopen failed: cannot locate symbol "PyExc_ValueError" referenced by "/data/data/org.tmarplatt.testapp.tmarpp/files/app/_python_bundle/site-packages/worldwrapper.so"
What could be going on? Since it's suggested in #43 to use -rdynamic for linking, I added the --export-dynamic flag into ldc's configuration, but it hasn't solved the problem.
If I can work this out I'll be able to contribute with a python-for-android recipe for building pyd-enabled modules. "Recipes" are wrapper scripts for patching, compiling and installing python modules with ARM architecture-specific requirements, which are included in the Android app package.
The text was updated successfully, but these errors were encountered: