kivy: python for android + C++ - python

I've used python-for_android to create a kivy based application running on android.
Some parts of my application have been optimized in c++ using cython.
I manage to compile all my code using python for android and a custom recipes.
My code also works perfectly with kivy under linux.
But on my android device, it failed to load some c++ function. For instance, I get the message :
ImportError: Cannot load library: reloc_library[1307]: 1839 cannot locate '_ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E'...
Any idea ?
Thanks

I've finally managed to make my code work using C++ under android.
There were two difficulties :
1 - Access to c++ header from the arm environment created by push_arm. I had to add the correct includes in my recipe, and modify the default CXX var :
#dirty hack
export C_INCLUDE="-I$ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/$TOOLCHAIN_VERSION/include/ -I$ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/$TOOLCHAIN_VERSION/libs/armeabi/include/"
export OLD_BOUBOU=$CC
export CC="$CXX $C_INCLUDE"
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
#try cp libgnustl_shared.so $LIBS_PATH/
try cp $ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_shared.so $LIBS_PATH/
export CC=$OLD_BOUBOU
2 - Find the shared library containing the libstl functions, and load it. This was the harder part :
After some research, I discover that stl functions are stored in libgnustl_shared.so, and not listdc++.so. So you have to embed this library in your apk.
This is the purpose of the line try cp $ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_shared.so $LIBS_PATH/
Then, you have to load it. I've modified :
src/src/org/renpy/android/PythonActivity.java
src/src/org/renpy/android/PythonService.java
by adding this line after the others System.loadLibrary() :
System.loadLibrary("gnustl_shared");

I am currently trying to build pybox2d (with swig) via python-for-android.
The build seems to be fine unit i try to import Box2D ( from the app on the actual android device) i get a
"cannot locate symbol __cxa_end_cleanup".
Unfortunately the above fix doies not help.
Any other ideas?
Update:
I could fix all issues.
I had to link against stlport_shared.
All my work is in my fork of https://github.com/DerThorsten/python-for-android/ . It works with newer ndks then the orginal python-for-android.
And it has Box2D.

Related

Boost Python "cannot open source file 'pyconfig.h'" when importing using "#include <boost\python.hpp>"

I am attempting to use Boost Python for a project. I have downloaded and build version 1.70 on Windows 10, and I am using Visual Studio Code. When attempting to import boost into my c++ project with the line:
#include <boost\python.hpp>
, I receive the following error:
cannot open source file "pyconfig.h" (dependency of "boost\python.hpp")
I have looked into similar issues, and the primary solution I have found was to edit user-config.jam to include the location of my python installation. I have done so, and the line within user-config.jam looks like this:
using python : 3.7 : C:\Users\broke\AppData\Local\Programs\Python\Python37 ;
After adding this line, I rebuilt Boost Python. This did nothing to remedy the issue. I would greatly appreciate help on this matter. Thank you.
you need to make sure the python/include folder is added to your includes. C:\Python\Python37\include for me on windows. You will also need to link the python library.

Issue with Linking Python C Extension to Another Library

I am in the process of developing a Python extension to allow a script running on a Raspberry Pi to control a sensor. The sensor manufacturer provided my organization with the source code to their C API, and I am trying to create a set of bindings to make the sensor accessible in Python scrips.
The makefile that came with the API source created a set of object files that I then linked together into a library (libvl53l1.a) using the command:
ar -cvq libvl53l1.a *.o
I then added this library to the setup.py script o my extension by adding this flag:
extra_compile_args=["-l:libvl53l1.a"]
The code, library, and setup.py script are currently in the same directory for convenience. Installing the library into Python using the command (python3 setup.py build_ext --inplace) runs without errors, however, when I try to import my library in a Python interpreter, the import fails because of an undefined symbol "VL53L1_WaitDeviceBooted" in the extension's .so file. Listing the symbols in libvl54l1.a:
nm libvl53l1.a | grep "VL53L1_WaitDeviceBooted"
shows that the library does expose a symbol of this name. Therefore, I believe that the linker is failing to link the extension with this static library. Is there a step I am missing that is causing this? I have also tried removing the .a extension as recommended in the Python documentation, to no avail.
Thank you
extra_compile_args=["-l:libvl53l1.a"]
This setting adds -l:... to the compilation command, but the compiler ignores that option, because it's a linking option, and no linking is done by the compiler.
You want: extra_link_args=["-lvl53l1"], which would add -lvl53l1 to the link command (the linker wouldn't ignore that option while performing the linking).

libpython3.6m.dylib vs libpython3.6.dylib

I'm working on creating an app from Python code using py2app.
Everything goes well until I run setup.py, then at the very end of it running I get this message: "ValueError:
'/Users/(my_computer_name)/anaconda3/lib/libpython3.6.dylib' does not exist"
It turns out there is a file there, just named slightly different: It asks for 'libpython3.6.dylib' and there is a file named 'libpython3.6m.dylib'
Any insight would be greatly appreciated, thank you!
Anaconda Python binaries are build with multithread support and that means the library generated will have the form *m.dylib ( see this Google Groups link )
You could create a symlink and try to build using py2app (I had issues with that).
Alternatively this worked for me: I had an equivalent virtualenv setup (which uses a Python Framework and makes py2app locate the library differently) and was able to build the application on that one.

Error on connecting to python libraries

I have a project that has code which will communicate with a python script and call python functions. In the proj file, i've added the includePath for the python header files, and added external python library to the project (python27.a). However the qt compiler gave me an error:
No rule to make target
/home/pgeng/work/OpenModelica-rev.9876.CSA/OMEdit/OMEditGUI/../../../../../../usr/lib/python2.7/libpython2.a
, needed by ../bin/OMEdit. Stop
What does this mean? How can i fix it? this is anything related to PyQt?
It seems like libpython2 is missing.
You will have to :
Find out what package provides this library.
You can Google for that.
Or search a repo for the lib.

python com component does not register when using libxml2 on win7

i've built a com component which utilizes libxml2 python bindings , the build is successfull but when i try to register the component i get "specified module could not be found , unable to load python dll" this is the error i get when the component is built using the bundle files option set as 1
if i build the component with bundle files set as 3 ,then i get a different error saying that the component was loaded but the call to DllRegisterServer Failed with error code 80040201
if the libxml2 import is removed all works fine.
any help wold be simply great.
thanks
Most likely, regsvr32.exe which registers you COM component couldn't find a DLL that your COM component needs.
I'm not familiar with Python COM components but is there some way you can run depends.exe on it? This is the usual way to track down binary dependency problems.

Categories

Resources