I wish to embed Python in a C++ Qt qmake project that has to be able to work on multiple platforms, like Linux, Android and Windows.
So far I've succeeded in the Linux part by doing the following:
In the .pro file I've included the Python C headers like this
# Python
unix {
LIBS += -L 3rdparty/python3.9 -lpython3.9
INCLUDEPATH += 3rdparty/python3.9
DEPENDPATH += 3rdparty/python3.9
}
For more info, in the .pro file, "unix" includes both Linux and Android
Next, in my cpp file, I've imported the Python header like this
extern "C" {
//For Python integration and avoiding name conflict with reserved Qt keywords slots, emit, and so on
#define IGNORE_CRYPT_H
#pragma push_macro("slots")
#undef slots
#include <Python.h>
#pragma pop_macro("slots")
}
I've made a slight modification to the Python.h file like this in order to avoid including crypt.h
#ifndef IGNORE_CRYPT_H
#include <crypt.h>
#endif
And finally, I can execute a simple Python print script from C++ like this
Py_Initialize();
std::string code = "print(\"hello there\")";
PyRun_SimpleString(code.c_str());
Py_Finalize();
Now, at last, when I compile this for Linux, my host OS, it works perfectly and I can see "hello there" is outputted to the console.
However, the problem starts when I try to compile this for Android. Compiling for Android for the architectures arm64-v8a and armeabi-v7a fails with these errors
/home/user/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lpython3.9
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile.Arm64-v8a:320: libMemento_arm64-v8a.so] Error 1
make[1]: Leaving directory '/tmp/memento-android-release'
make: *** [Makefile:75: arm64-v8a-all] Error 2
make: *** Waiting for unfinished jobs....
In file included from /path/to/source/code/backend.cpp:26:
In file included from /path/to/source/code/3rdparty/python3.9/Python.h:65:
/path/to/source/code/3rdparty/python3.9/pyport.h:741:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
^
1 error generated.
make[1]: *** [Makefile.Armeabi-v7a:1664: armeabi-v7a/backend.o] Error 1
make[1]: Leaving directory '/tmp/memento-android-release'
make: *** [Makefile:47: armeabi-v7a-all] Error 2
13:32:57: The process "/home/user/Android/Sdk/ndk/21.3.6528147/prebuilt/linux-x86_64/bin/make" exited with code 2.
Error while building/deploying project memento (kit: Android Qt 5.15.2 (android) Clang Multi-Abi)
When executing step "Make"
Basically, there are 2 errors that I don't know how to solve - it can't find lpython3.9, and the "LONG_BIT" definition is wrong. Any ideas on how to solve this and compile the project for Android?
Aucun commentaire:
Enregistrer un commentaire