Issue35997
Created on 2019-02-14 20:36 by muhzi, last changed 2022-04-11 14:59 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| xcompile-py3.sh | muhzi, 2019-02-14 21:55 | |||
| Messages (8) | |||
|---|---|---|---|
| msg335560 - (view) | Author: (muhzi) | Date: 2019-02-14 20:36 | |
I cross compiled python for android x86_64, and the interpreter works fine, no problems. But when I compiled some other extension and try to import it. I get an import error as such the imported shared library fails to locate the symbol "PyBool_Type". ImportError: dlopen failed: cannot locate symbol "PyBool_Type" referenced by .... The extension was compiled with -I && -L flags pointing to the Python installation include and lib folders. |
|||
| msg335563 - (view) | Author: Stéphane Wirtel (matrixise) * ![]() |
Date: 2019-02-14 21:06 | |
Can you see the symbols when you use nm or readelf? |
|||
| msg335565 - (view) | Author: Stéphane Wirtel (matrixise) * ![]() |
Date: 2019-02-14 21:11 | |
if you have compiled python with --enable-shared you will get a lib/libpython3.Xdm.so file and you can use nm -D lib/libpython3.Xdm.so | grep PyBool_Type nm --debug-syms lib/libpython3.8dm.so | grep PyBool 0000000000077696 T PyBool_FromLong 0000000000328d20 D PyBool_Type I think it's a problem with your compilation. Could you explain how do you cross-compile for android? Thank you |
|||
| msg335567 - (view) | Author: (muhzi) | Date: 2019-02-14 21:26 | |
Yes, the symbols are there.
And here is how I cross compiled Python:
export CC="${ANDROID_TARGET}${ANDROID_API}-clang"
export CXX="$CC++"
# environment variables for binary utils..
export AR="$BIN_UTILS_PREFIX-ar"
export LD="$BIN_UTILS_PREFIX-ld"
export AS="$BIN_UTILS_PREFIX-as"
export STRIP="$BIN_UTILS_PREFIX-strip"
export RANLIB="$BIN_UTILS_PREFIX-ranlib"
export READELF="$BIN_UTILS_PREFIX-readelf"
# compiler and linker flags
export CFLAGS="-fPIE -fPIC"
export LDFLAGS="-fuse-ld=lld -Wl,--rpath=../lib"
export CONFIG_SITE="config.site"
CONFIG_BUILD="$(uname -m)-linux-gnu"
CONFIG_ARGS="--enable-shared --disable-ipv6"
CONFIG_PREFIX="$PYTHON_PATH/output/$ARCH-android"
$PYTHON_PATH/configure --host=$ANDROID_TARGET --build=$CONFIG_BUILD --prefix=$CONFIG_PREFIX $CONFIG_ARGS
make -C $PYTHON_PATH
make -C $PYTHON_PATH install
|
|||
| msg335568 - (view) | Author: Stéphane Wirtel (matrixise) * ![]() |
Date: 2019-02-14 21:37 | |
Thank you, but I think there is missing info with your script. Do you have a shell script to share? What are the values of: ANDROID_TARGET ANDROID_API CC++ BIN_UTILS_PREFIX etc... For example, if I want to use a docker image on my Fedora, how can I compile Python for Android from my Fedora or Debian x86? Thank you |
|||
| msg335570 - (view) | Author: (muhzi) | Date: 2019-02-14 21:54 | |
OK, I uploaded it. I give the path for NDK then it determines those values for the target architecture, in my case I use it for x86_64. |
|||
| msg335625 - (view) | Author: Xavier de Gaye (xdegaye) * ![]() |
Date: 2019-02-15 17:33 | |
It is not yet possible to cross-compile python extensions. The reason is that _init_posix() in Lib/sysconfig.py still reads the sysconfigdata module of the native compiler instead of the sysconfigdata of the cross-built one. See the patch in issue #28833. |
|||
| msg335665 - (view) | Author: (muhzi) | Date: 2019-02-16 02:31 | |
Ah! I used the option -Bsymbolic while linking the extension to make it work and it did, but I figure it is not ideal. I will be checking that patch! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:11 | admin | set | github: 80178 |
| 2019-12-10 08:07:15 | xdegaye | set | nosy:
- xdegaye |
| 2019-02-16 02:31:58 | muhzi | set | messages:
+ msg335665 components: + Extension Modules, - Regular Expressions |
| 2019-02-15 17:33:29 | xdegaye | set | messages: + msg335625 |
| 2019-02-14 21:55:59 | muhzi | set | files: + xcompile-py3.sh |
| 2019-02-14 21:55:42 | muhzi | set | files: - xcompile-py3.sh |
| 2019-02-14 21:54:09 | muhzi | set | files:
+ xcompile-py3.sh messages: + msg335570 |
| 2019-02-14 21:37:50 | matrixise | set | messages: + msg335568 |
| 2019-02-14 21:26:10 | muhzi | set | messages: + msg335567 |
| 2019-02-14 21:11:18 | matrixise | set | messages: + msg335565 |
| 2019-02-14 21:06:18 | matrixise | set | nosy:
+ matrixise messages: + msg335563 |
| 2019-02-14 20:36:32 | muhzi | create | |

