Skip to content
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

Nuitka in specific Android environments #1163

Closed
liukangcc opened this issue Jul 17, 2021 · 23 comments
Closed

Nuitka in specific Android environments #1163

liukangcc opened this issue Jul 17, 2021 · 23 comments
Assignees
Labels
enhancement An improvement rather than a bug

Comments

@liukangcc
Copy link

liukangcc commented Jul 17, 2021

I installed Termux on my Android phone And installed Python 3.9 and Nuitka, But when I use nuitka --module, I get the wrong code :

python -m nuitka --module hello.py --output-dir=out

.../usr/python $ python -m nuitka --module hello.py --output-dir=out
Nuitka-Options:INFO: Used command line options: --module hello.py --output-dir=out
Nuitka:INFO: Starting Python compilation with Nuitka '0.6.16.2' on Python '3.9' commercial None.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C level backend compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: gcc (gcc).
Backend C:   0%|                                                                            | 0/11clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
Backend C:   9%|██████▉                                                                     | 1/11clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
Backend C:  27%|████████████████████▋                                                       | 3/11clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
Backend C:  45%|██████████████████████████████████▌                                         | 5/11clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
scons: *** [__constants.os] Error 1
scons: *** [__constants_data.os] Error 1
scons: *** [__helpers.os] Error 1
scons: *** [__loader.os] Error 1
scons: *** [module.hello.os] Error 1
scons: *** [static_src/CompiledCellType.os] Error 1
clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
Backend C:  64%|████████████████████████████████████████████████▎                           | 7/11scons: *** [static_src/CompiledFunctionType.os] Error 1
clang-12: error: unknown argument: '-fpartial-inlining'
clang-12: error: unknown argument: '-ftrack-macro-expansion=0'
clang-12: error: unknown argument: '-fcompare-debug-second'
scons: *** [static_src/CompiledGeneratorType.os] Error 1

Environment

.../usr/python $ python --version
Python 3.9.6
.../python/out $ clang --version
clang version 12.0.0
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin
.../python/out $ gcc --version
clang version 12.0.0
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin

I can use the option --clang to generate .so file,but the .so file is not work:

.../usr/python $ python -m nuitka --module --clang hello.py --output-dir=out
Nuitka-Options:INFO: Used command line options: --module --clang hello.py --output-dir=out
Nuitka:INFO: Starting Python compilation with Nuitka '0.6.16.2' on Python '3.9' commercial None.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C level backend compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: clang (clang).
Nuitka-Scons:WARNING: You are not using ccache.
Nuitka:INFO: Keeping build directory 'out/hello.build'.
Nuitka:INFO: Successfully created 'out/hello.cpython-39.so'.
.../usr/python $ cd out/
.../python/out $ mv hello.cpython-39.so hello.so
.../python/out $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen failed: cannot locate symbol "PyFloat_Type" referenced by "/data/data/com.termux/files/usr/python/out/hello.so"...

Can you give me some help or advice on using Nuitka to generate dynamic library files on Android?

@kayhayen
Copy link
Member

Interesting. So far I think people have cross compiled standalone mode programs only. Using clang mode is clearly a must, otherwise gcc specific options will be used, or at least version specific options will be wrong. If your python is statically compiled, it may not expose the needed symbols for extension modules. This is a matter of how the Python is built. Does it support extension modules, or is it a stripped down version that has things compiled in.

@liukangcc
Copy link
Author

I use cython to generate. So file, it seems to work normally :

.../files/python $ python setup.py build_ext
running build_ext
building 'hello' extension
aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -fPIC -I/data/data/com.termux/files/usr/include/python3.9 -c hello.c -o build/temp.linux-aarch64-3.9/hello.o
aarch64-linux-android-clang -shared -L/data/data/com.termux/files/usr/lib -Wl,-rpath=/data/data/com.termux/files/usr/lib -fopenmp -static-openmp -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -landroid-support -L/home/builder/.termux-build/_cache/android-r21d-api-24-v4/sysroot/usr/lib -L/data/data/com.termux/files/usr/lib -Wl,-rpath=/data/data/com.termux/files/usr/lib -fopenmp -static-openmp -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -landroid-support -L/home/builder/.termux-build/_cache/android-r21d-api-24-v4/sysroot/usr/lib build/temp.linux-aarch64-3.9/hello.o -L/data/data/com.termux/files/usr/lib -lpython3.9 -o build/lib.linux-aarch64-3.9/hello.cpython-39.so

.../files/python $ cd build/
.../python/build $ ls
lib.linux-aarch64-3.9  temp.linux-aarch64-3.9
.../python/build $ cd lib.linux-aarch64-3.9/
.../build/lib.linux-aarch64-3.9 $ ls
hello.so  test  test.c
.../build/lib.linux-aarch64-3.9 $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> hello.hi_test()
hello, world

@kayhayen
Copy link
Member

You should try bdist_nuitka target then.

@liukangcc
Copy link
Author

You should try bdist_nuitka target then.

How do I use bdist_nuitka ?

@ghost
Copy link

ghost commented Jul 19, 2021

Few things to consider when using Termux:

  1. https://wiki.termux.com/wiki/Differences_from_Linux
  2. Symbol visibility works a bit differently on Android: Shared library symbols not visible on dlopen()? android/ndk#201

@kayhayen
Copy link
Member

Using python setup.py bdist_nuitka would be a first step. I would recommend making it work on a normal Linux first, then try it there. It would have to abstract the platform differences.

@kayhayen
Copy link
Member

Interestingly enough, I am having similar issues with statically built Pythons on Linux with LTO right now. Nuitka is missing out on some linker flags that make sure symbols get exported. A solution for that is likely a solution for this here too.

@liukangcc
Copy link
Author

liukangcc commented Jul 20, 2021

I successfully generated the .so file on Android using Nuitka, and it can be imported and works:

image

(venv) ~/python/udb-tools $ venv/bin/python -m nuitka --module --output-dir=out --clang --show-scons --include-package=nuitka_test nuitka_test
Nuitka-Options:INFO: Used command line options: --module --output-dir=out --clang --show-scons --include-package=nuitka_test nuitka_test
Nuitka:INFO: Starting Python compilation with Nuitka '0.6.16.2' on Python '3.9' commercial None.
Nuitka-Recursion:WARNING: Recursed to package 'nuitka_test' at '/home/python/udb-tools/nuitka_test' twice.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C level backend compilation via Scons.
Scons command: /home/python/udb-tools/venv/bin/python -W ignore /home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/inline_copy/bin/scons.py -f /home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/Backend.scons --jobs 8 --warn=no-deprecated --no-site-dir --debug=explain,stacktrace result_name=/home/python/udb-tools/out/nuitka_test source_dir=. nuitka_python=false debug_mode=false python_debug=false unstripped_mode=false module_mode=true full_compat=false experimental= trace_mode=false python_version=3.9 target_arch=aarch64 python_prefix=/usr nuitka_src=/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build module_count=3 module_suffix=.cpython-39.so clang_mode=true show_scons=true
scons: Reading SConscript files ...
Nuitka-Scons:INFO: CC '/data/data/com.termux/files/usr/bin/gcc' version check gives (12, 0, 0)
Nuitka-Scons:INFO: Initial CC: 'gcc'
Nuitka-Scons:INFO: Initial CCVERSION: (12, 0, 0)
Nuitka-Scons:INFO: Backend C compiler: clang (clang).
Nuitka-Scons:INFO: Modes for this compiler are: {'gcc_mode': True, 'clang_mode': True, 'clangcl_mode': False, 'mingw_mode': False, 'msvc_mode': False}
Nuitka-Scons:INFO: Using C11 mode: True
Scons: Compiler used /data/data/com.termux/files/usr/bin/clang
Nuitka-Scons:INFO: Using resource mode: 'incbin'.
Scons: Told to run compilation on 8 CPUs.
Scons: Launching target: ['/home/python/udb-tools/out/nuitka_test.cpython-39.so']
Backend C:   0%|                                                                                                       | 0/12scons: done reading SConscript files.
scons: Building targets ...
Nuitka-Scons:INFO: CC '/bin/gcc' version check gives (12, 0, 0)
                                                                                                                            scons: building `__constants.os' because it doesn't exist                                                               | 0/12
clang -o __constants.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __constants.c
scons: building `__constants_data.os' because it doesn't exist
clang -o __constants_data.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __constants_data.c
scons: building `__helpers.os' because it doesn't exist
clang -o __helpers.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __helpers.c
scons: building `__loader.os' because it doesn't exist
clang -o __loader.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __loader.c
scons: building `module.nuitka_test.os' because it doesn't exist
clang -o module.nuitka_test.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src module.nuitka_test.c
scons: building `module.nuitka_test.test.os' because it doesn't exist
clang -o module.nuitka_test.test.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src module.nuitka_test.test.c
                                                                                                                            scons: building `static_src/CompiledCellType.os' because it doesn't exist                                               | 1/12
clang -o static_src/CompiledCellType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledCellType.c
scons: building `static_src/CompiledFunctionType.os' because it doesn't exist
clang -o static_src/CompiledFunctionType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledFunctionType.c
scons: building `static_src/CompiledGeneratorType.os' because it doesn't exist
clang -o static_src/CompiledGeneratorType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledGeneratorType.c
                                                                                                                            scons: building `static_src/CompiledCodeHelpers.os' because it doesn't exist                                            | 3/12
clang -o static_src/CompiledCodeHelpers.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledCodeHelpers.c
scons: building `static_src/InspectPatcher.os' because it doesn't exist
clang -o static_src/InspectPatcher.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/InspectPatcher.c
scons: building `static_src/MetaPathBasedLoader.os' because it doesn't exist
clang -o static_src/MetaPathBasedLoader.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/usr/include/python3.9 -I. -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/MetaPathBasedLoader.c
                                                                                                                            scons: building `/home/python/udb-tools/out/nuitka_test.cpython-39.so' because it doesn't exist████████████████████████| 12/12
clang -o /home/python/udb-tools/out/nuitka_test.cpython-39.so -z noexecstack -shared __constants.os __constants_data.os __helpers.os __loader.os module.nuitka_test.os module.nuitka_test.test.os static_src/CompiledCellType.os static_src/CompiledFunctionType.os static_src/CompiledGeneratorType.os static_src/CompiledCodeHelpers.os static_src/InspectPatcher.os static_src/MetaPathBasedLoader.os -ldl -lm -lpython3
                                                                                                                            scons: done building targets.                                                                                           | 13/?
Nuitka-Scons:WARNING: You are not using ccache.
Nuitka:INFO: Keeping build directory 'out/nuitka_test.build'.
Nuitka:INFO: Successfully created 'out/nuitka_test.cpython-39.so'.

(venv) ~/python/udb-tools $ cd out/
(venv) ~/.../udb-tools/out $ mv nuitka_test.cpython-39.so nuitka_test.so
(venv) ~/.../udb-tools/out $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nuitka_test
>>> from nuitka_test.test import *
>>> test_hi()
hello, world
>>>

@kayhayen
Copy link
Member

Does it mean, it comes down to Nuitka not being allowed to use the version specific extension? Is the mv nuitka_test.cpython-39.so nuitka_test.so really needed? I think Nuitka picks the extension filename from what Python claims to accept, so this definitely shouldn't be needed.

Compiling packages is a bit ugly with having to include them. I never got around to adding a --package mode.

Basically this is about hacking things, so --clang is the default in that setup. Any idea, how to recognize it. I was thinking, it might be best, if gcc was detected to be actually a clang. Can you tell me if which gcc happens to be a symlink maybe?

@liukangcc
Copy link
Author

I just modified the backend.scons file:

image

@liukangcc
Copy link
Author

mv nuitka_test.cpython-39. so nuitka_test. so just for ease of use .

@liukangcc
Copy link
Author

if not use --package mode, the module will be not found, i don't know why:

~/python/udb-tools $ venv/bin/python -m nuitka --module --output-dir=out --clang --show-scons nuitka_test
Nuitka-Options:INFO: Used command line options: --module --output-dir=out --clang --show-scons nuitka_test
Nuitka:INFO: Starting Python compilation with Nuitka '0.6.16.2' on Python '3.9' commercial None.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C level backend compilation via Scons.
Scons command: /data/data/com.termux/files/home/python/udb-tools/venv/bin/python -W ignore /data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/inline_copy/bin/scons.py -f /data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/Backend.scons --jobs 8 --warn=no-deprecated --no-site-dir --debug=explain,stacktrace result_name=/data/data/com.termux/files/home/python/udb-tools/out/nuitka_test source_dir=. nuitka_python=false debug_mode=false python_debug=false unstripped_mode=false module_mode=true full_compat=false experimental= trace_mode=false python_version=3.9 target_arch=aarch64 python_prefix=/data/data/com.termux/files/usr nuitka_src=/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build module_count=2 module_suffix=.cpython-39.so clang_mode=true show_scons=true
scons: Reading SConscript files ...
Nuitka-Scons:INFO: CC '/data/data/com.termux/files/usr/bin/gcc' version check gives (12, 0, 0)
Nuitka-Scons:INFO: Initial CC: 'gcc'
Nuitka-Scons:INFO: Initial CCVERSION: (12, 0, 0)
Nuitka-Scons:INFO: Backend C compiler: clang (clang).
Nuitka-Scons:INFO: Modes for this compiler are: {'gcc_mode': True, 'clang_mode': True, 'clangcl_mode': False, 'mingw_mode': False, 'msvc_mode': False}
Nuitka-Scons:INFO: Using C11 mode: True
Scons: Compiler used /data/data/com.termux/files/usr/bin/clang
Nuitka-Scons:INFO: Using resource mode: 'incbin'.
Scons: Told to run compilation on 8 CPUs.
Scons: Launching target: ['/data/data/com.termux/files/home/python/udb-tools/out/nuitka_test.cpython-39.so']
Backend C:   0%|                                                                            | 0/11scons: done reading SConscript files.
scons: Building targets ...
scons: building `__constants.os' because it doesn't exist
clang -o __constants.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __constants.c
scons: building `__constants_data.os' because it doesn't exist
clang -o __constants_data.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __constants_data.c
scons: building `__helpers.os' because it doesn't exist
clang -o __helpers.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __helpers.c
scons: building `__loader.os' because it doesn't exist
clang -o __loader.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src __loader.c
scons: building `module.nuitka_test.os' because it doesn't exist
clang -o module.nuitka_test.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src module.nuitka_test.c
scons: building `static_src/CompiledCellType.os' because it doesn't exist
clang -o static_src/CompiledCellType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledCellType.c
Backend C:   9%|██████▉                                                                     | 1/11scons: building `static_src/CompiledFunctionType.os' because it doesn't exist
clang -o static_src/CompiledFunctionType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledFunctionType.c
Backend C:  18%|█████████████▊                                                              | 2/11scons: building `static_src/CompiledGeneratorType.os' because it doesn't exist
clang -o static_src/CompiledGeneratorType.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledGeneratorType.c
Backend C:  55%|█████████████████████████████████████████▍                                  | 6/11scons: building `static_src/CompiledCodeHelpers.os' because it doesn't exist
clang -o static_src/CompiledCodeHelpers.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/CompiledCodeHelpers.c
scons: building `static_src/InspectPatcher.os' because it doesn't exist
clang -o static_src/InspectPatcher.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/InspectPatcher.c
scons: building `static_src/MetaPathBasedLoader.os' because it doesn't exist
clang -o static_src/MetaPathBasedLoader.os -c -std=c11 -fvisibility=hidden -fwrapv -w -fvisibility=hidden -fvisibility-inlines-hidden -O3 -pipe -fPIC -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=0 -D_NUITKA_MODULE -I/data/data/com.termux/files/usr/include/python3.9 -I. -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/include -I/data/data/com.termux/files/home/python/udb-tools/venv/lib/python3.9/site-packages/nuitka/build/static_src static_src/MetaPathBasedLoader.c
Backend C: 100%|███████████████████████████████████████████████████████████████████████████| 11/11scons: building `/data/data/com.termux/files/home/python/udb-tools/out/nuitka_test.cpython-39.so' because it doesn't exist
clang -o /data/data/com.termux/files/home/python/udb-tools/out/nuitka_test.cpython-39.so -z noexecstack -shared __constants.os __constants_data.os __helpers.os __loader.os module.nuitka_test.os static_src/CompiledCellType.os static_src/CompiledFunctionType.os static_src/CompiledGeneratorType.os static_src/CompiledCodeHelpers.os static_src/InspectPatcher.os static_src/MetaPathBasedLoader.os -ldl -lm -lpython3
Backend C:   0%|                                                                            | 12/?scons: done building targets.
Nuitka-Scons:WARNING: You are not using ccache.
Nuitka:INFO: Keeping build directory 'out/nuitka_test.build'.
Nuitka:INFO: Successfully created 'out/nuitka_test.cpython-39.so'.
~/python/udb-tools $ cd out/
~/.../udb-tools/out $ mv nuitka_test.cpython-39.so nuitka_test.so
~/.../udb-tools/out $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from nuitka_test.test import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nuitka_test.test'

@kayhayen
Copy link
Member

well, the module is the init only, and that's not containing the code of the "test" submodule then. With --package, I meant, there ought to be a way to compile a package without having to specify a filename for the package, and then include the package into the compilation of that.

Right now, the --module mode has a very ugly user interface, esp. as modules do not really work well through filenames. It's an artifcat of how nuitka works for executables, where the main program is NOT really a module that is importable. Maybe this motivates me, to at least make it more automatic, or warn about it, or both. Making a single module out of a package directory makes no sense if there is other modules below at least. But the user manual describes how to do it actually pretty well. It's just that not everybody is good at reading. Including myself. :)

@kayhayen
Copy link
Member

So, the linking against python3 is not what Nuitka does normally, extension modules do not link against libraries at all, but instead get their symbols from python binary. Can you provide nm -gD which python`` output, is it not having symbols?

@liukangcc
Copy link
Author

not linking python:

(venv) ~/python/out $ nm nuitka_test.cpython-39.so -gD
                 U PyArg_ParseTuple
                 U PyArg_ParseTupleAndKeywords
                 U PyArg_UnpackTuple
                 U PyAsyncGen_Type
                 U PyBaseObject_Type
                 U PyBool_Type
                 U PyBuffer_Release
                 U PyByteArray_FromObject
                 U PyByteArray_FromStringAndSize
                 U PyByteArray_Type
                 U PyBytes_FromString
                 U PyBytes_FromStringAndSize
                 U PyBytes_Type
                 U PyCFunction_Type
                 U PyCMethod_New
                 U PyCallIter_Type
                 U PyCallable_Check
                 U PyCapsule_New
                 U PyCode_NewWithPosOnlyArgs
                 U PyCode_Type
                 U PyComplex_FromDoubles
                 U PyComplex_Type
                 U PyCoro_Type
                 U PyDict_DelItem
                 U PyDict_DelItemString
                 U PyDict_GetItem
                 U PyDict_GetItemString
                 U PyDict_New
                 U PyDict_Next
                 U PyDict_SetItem
                 U PyDict_SetItemString
                 U PyDict_Type
                 U PyEllipsis_Type
                 U PyErr_BadArgument
                 U PyErr_ExceptionMatches
                 U PyErr_Format
                 U PyErr_GivenExceptionMatches
                 U PyErr_NoMemory
                 U PyErr_NormalizeException
                 U PyErr_Print
                 U PyErr_PrintEx
                 U PyErr_WarnEx
                 U PyErr_WriteUnraisable
                 U PyEval_EvalCode
                 U PyEval_EvalCodeEx
                 U PyEval_EvalFrameEx
                 U PyEval_GetFrame
                 U PyEval_GetFuncName
                 U PyExc_AttributeError
                 U PyExc_GeneratorExit
                 U PyExc_ImportError
                 U PyExc_ImportWarning
                 U PyExc_IndexError
                 U PyExc_KeyError
                 U PyExc_NameError
                 U PyExc_OverflowError
                 U PyExc_RuntimeError
                 U PyExc_StopAsyncIteration
                 U PyExc_StopIteration
                 U PyExc_SystemError
                 U PyExc_TypeError
                 U PyExc_UnboundLocalError
                 U PyExc_ValueError
                 U PyExc_ZeroDivisionError
                 U PyException_GetContext
                 U PyException_GetTraceback
                 U PyException_SetCause
                 U PyException_SetContext
                 U PyFloat_FromDouble
                 U PyFloat_Type
                 U PyFrame_GetLineNumber
                 U PyFrame_New
                 U PyFrame_Type
                 U PyFrozenSet_New
                 U PyFrozenSet_Type
                 U PyFunction_Type
                 U PyGen_Type
                 U PyImport_ExecCodeModule
                 U PyImport_ExecCodeModuleEx
                 U PyImport_FrozenModules
                 U PyImport_GetModule
                 U PyImport_GetModuleDict
                 U PyImport_ImportFrozenModule
                 U PyImport_ImportModule
                 U PyIndex_Check
000000000000a618 T PyInit_nuitka_test
                 U PyIter_Next
                 U PyList_Insert
                 U PyList_New
                 U PyList_SetItem
                 U PyList_Type
                 U PyLong_AsLong
                 U PyLong_AsLongAndOverflow
                 U PyLong_FromLong
                 U PyLong_FromLongLong
                 U PyLong_FromSsize_t
                 U PyLong_FromString
                 U PyLong_FromUnicodeObject
                 U PyLong_FromUnsignedLongLong
                 U PyLong_Type
                 U PyMapping_Check
                 U PyMarshal_ReadObjectFromString
                 U PyMem_Malloc
                 U PyMem_Realloc
                 U PyMethod_Type
                 U PyModuleDef_Type
                 U PyModule_AddObject
                 U PyModule_Create2
                 U PyModule_ExecDef
                 U PyModule_FromDefAndSpec2
                 U PyModule_GetDef
                 U PyModule_GetDict
                 U PyModule_GetFilenameObject
                 U PyModule_GetName
                 U PyModule_NewObject
                 U PyModule_Type
                 U PyNumber_Add
                 U PyNumber_AsSsize_t
                 U PyNumber_FloorDivide
                 U PyNumber_InPlaceAdd
                 U PyNumber_InPlaceLshift
                 U PyNumber_InPlaceMultiply
                 U PyNumber_Index
                 U PyNumber_Negative
                 U PyNumber_Subtract
                 U PyNumber_ToBase
                 U PyObject_Call
                 U PyObject_CallFunctionObjArgs
                 U PyObject_CallMethodObjArgs
                 U PyObject_CallObject
                 U PyObject_ClearWeakRefs
                 U PyObject_Free
                 U PyObject_GC_Del
                 U PyObject_GC_Track
                 U PyObject_GC_UnTrack
                 U PyObject_GenericGetAttr
                 U PyObject_GenericSetAttr
                 U PyObject_GetAttr
                 U PyObject_GetAttrString
                 U PyObject_GetBuffer
                 U PyObject_GetIter
                 U PyObject_IsInstance
                 U PyObject_IsSubclass
                 U PyObject_IsTrue
                 U PyObject_LengthHint
                 U PyObject_Malloc
                 U PyObject_Realloc
                 U PyObject_Repr
                 U PyObject_RichCompare
                 U PyObject_RichCompareBool
                 U PyObject_SelfIter
                 U PyObject_SetAttr
                 U PyObject_SetAttrString
                 U PyObject_Size
                 U PyObject_Str
                 U PyRange_Type
                 U PySeqIter_Type
                 U PySequence_Check
                 U PySequence_GetItem
                 U PySequence_InPlaceConcat
                 U PySet_Add
                 U PySet_New
                 U PySet_Type
                 U PySlice_New
                 U PySlice_Type
                 U PyStructSequence_InitType
                 U PyStructSequence_New
                 U PySuper_Type
                 U PySys_GetObject
                 U PyTraceBack_Type
                 U PyTuple_New
                 U PyTuple_Pack
                 U PyTuple_Type
                 U PyType_GetFlags
                 U PyType_IsSubtype
                 U PyType_Ready
                 U PyType_Type
                 U PyUnicode_AsUTF8
                 U PyUnicode_AsUnicode
                 U PyUnicode_Concat
                 U PyUnicode_DecodeUTF8
                 U PyUnicode_FindChar
                 U PyUnicode_Format
                 U PyUnicode_FromFormat
                 U PyUnicode_FromOrdinal
                 U PyUnicode_FromString
                 U PyUnicode_FromStringAndSize
                 U PyUnicode_InternInPlace
                 U PyUnicode_New
                 U PyUnicode_Substring
                 U PyUnicode_Type
                 U Py_BuildValue
                 U Py_CompileStringExFlags
                 U Py_Exit
                 U Py_GenericAlias
                 U Py_GenericAliasType
                 U _PyArg_NoKeywords
                 U _PyAsyncGenWrappedValue_Type
                 U _PyByteArray_empty_string
                 U _PyBytes_Resize
                 U _PyDict_NewPresized
                 U _PyErr_FormatFromCause
                 U _PyGen_FetchStopIterationValue
                 U _PyGen_SetStopIterationValue
                 U _PyImport_FixupExtensionObject
                 U _PyLong_New
                 U _PyObject_GC_Malloc
                 U _PyObject_GC_New
                 U _PyObject_GC_Resize
                 U _PyObject_HasLen
                 U _PyObject_New
                 U _PyRuntime
                 U _PySet_NextEntry
                 U _PyType_Lookup
                 U _PyUnicode_Ready
                 U _Py_Dealloc
                 U _Py_EllipsisObject
                 U _Py_FalseStruct
                 U _Py_NewReference
                 U _Py_NoneStruct
                 U _Py_NotImplementedStruct
                 U _Py_PackageContext
                 U _Py_TrueStruct
                 U __cxa_atexit@LIBC
                 U __cxa_finalize@LIBC
                 U __errno@LIBC
                 U __register_atfork@LIBC
                 U abort@LIBC
                 U dirname@LIBC
                 U dladdr@LIBC
                 U dlerror@LIBC
                 U dlopen@LIBC
                 U dlsym@LIBC
                 U fmod@LIBC
                 U getenv@LIBC
                 U getpid@LIBC
                 U gettimeofday@LIBC
                 U mbstowcs@LIBC
                 U memcmp@LIBC
                 U memcpy@LIBC
                 U memset@LIBC
                 U pow@LIBC
                 U printf@LIBC
                 U puts@LIBC
                 U snprintf@LIBC
                 U strcasecmp@LIBC
                 U strcat@LIBC
                 U strchr@LIBC
                 U strcmp@LIBC
                 U strcpy@LIBC
                 U strdup@LIBC
                 U strlen@LIBC
                 U strncmp@LIBC
                 U strncpy@LIBC
                 U strrchr@LIBC
                 U vsprintf@LIBC
                 U wcslen@LIBC
(venv) ~/python/out $ ldd nuitka_test.cpython-39.so
libdl.so
libm.so
libc.so
(venv) ~/python/out $ mv nuitka_test.cpython-39.so nuitka_test.so
(venv) ~/python/out $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nuitka_test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen failed: cannot locate symbol "PyFloat_Type" referenced by "/data/data/com.termux/files/home/python/out/nuitka_test.so"...

linking python3

nm nuitka_test.cpython-39.so -gD
                 U PyArg_ParseTuple
                 U PyArg_ParseTupleAndKeywords
                 U PyArg_UnpackTuple
                 U PyAsyncGen_Type
                 U PyBaseObject_Type
                 U PyBool_Type
                 U PyBuffer_Release
                 U PyByteArray_FromObject
                 U PyByteArray_FromStringAndSize
                 U PyByteArray_Type
                 U PyBytes_FromString
                 U PyBytes_FromStringAndSize
                 U PyBytes_Type
                 U PyCFunction_Type
                 U PyCMethod_New
                 U PyCallIter_Type
                 U PyCallable_Check
                 U PyCapsule_New
                 U PyCode_NewWithPosOnlyArgs
                 U PyCode_Type
                 U PyComplex_FromDoubles
                 U PyComplex_Type
                 U PyCoro_Type
                 U PyDict_DelItem
                 U PyDict_DelItemString
                 U PyDict_GetItem
                 U PyDict_GetItemString
                 U PyDict_New
                 U PyDict_Next
                 U PyDict_SetItem
                 U PyDict_SetItemString
                 U PyDict_Type
                 U PyEllipsis_Type
                 U PyErr_BadArgument
                 U PyErr_ExceptionMatches
                 U PyErr_Format
                 U PyErr_GivenExceptionMatches
                 U PyErr_NoMemory
                 U PyErr_NormalizeException
                 U PyErr_Print
                 U PyErr_PrintEx
                 U PyErr_WarnEx
                 U PyErr_WriteUnraisable
                 U PyEval_EvalCode
                 U PyEval_EvalCodeEx
                 U PyEval_EvalFrameEx
                 U PyEval_GetFrame
                 U PyEval_GetFuncName
                 U PyExc_AttributeError
                 U PyExc_GeneratorExit
                 U PyExc_ImportError
                 U PyExc_ImportWarning
                 U PyExc_IndexError
                 U PyExc_KeyError
                 U PyExc_NameError
                 U PyExc_OverflowError
                 U PyExc_RuntimeError
                 U PyExc_StopAsyncIteration
                 U PyExc_StopIteration
                 U PyExc_SystemError
                 U PyExc_TypeError
                 U PyExc_UnboundLocalError
                 U PyExc_ValueError
                 U PyExc_ZeroDivisionError
                 U PyException_GetContext
                 U PyException_GetTraceback
                 U PyException_SetCause
                 U PyException_SetContext
                 U PyFloat_FromDouble
                 U PyFloat_Type
                 U PyFrame_GetLineNumber
                 U PyFrame_New
                 U PyFrame_Type
                 U PyFrozenSet_New
                 U PyFrozenSet_Type
                 U PyFunction_Type
                 U PyGen_Type
                 U PyImport_ExecCodeModule
                 U PyImport_ExecCodeModuleEx
                 U PyImport_FrozenModules
                 U PyImport_GetModule
                 U PyImport_GetModuleDict
                 U PyImport_ImportFrozenModule
                 U PyImport_ImportModule
                 U PyIndex_Check
000000000000a698 T PyInit_nuitka_test
                 U PyIter_Next
                 U PyList_Insert
                 U PyList_New
                 U PyList_SetItem
                 U PyList_Type
                 U PyLong_AsLong
                 U PyLong_AsLongAndOverflow
                 U PyLong_FromLong
                 U PyLong_FromLongLong
                 U PyLong_FromSsize_t
                 U PyLong_FromString
                 U PyLong_FromUnicodeObject
                 U PyLong_FromUnsignedLongLong
                 U PyLong_Type
                 U PyMapping_Check
                 U PyMarshal_ReadObjectFromString
                 U PyMem_Malloc
                 U PyMem_Realloc
                 U PyMethod_Type
                 U PyModuleDef_Type
                 U PyModule_AddObject
                 U PyModule_Create2
                 U PyModule_ExecDef
                 U PyModule_FromDefAndSpec2
                 U PyModule_GetDef
                 U PyModule_GetDict
                 U PyModule_GetFilenameObject
                 U PyModule_GetName
                 U PyModule_NewObject
                 U PyModule_Type
                 U PyNumber_Add
                 U PyNumber_AsSsize_t
                 U PyNumber_FloorDivide
                 U PyNumber_InPlaceAdd
                 U PyNumber_InPlaceLshift
                 U PyNumber_InPlaceMultiply
                 U PyNumber_Index
                 U PyNumber_Negative
                 U PyNumber_Subtract
                 U PyNumber_ToBase
                 U PyObject_Call
                 U PyObject_CallFunctionObjArgs
                 U PyObject_CallMethodObjArgs
                 U PyObject_CallObject
                 U PyObject_ClearWeakRefs
                 U PyObject_Free
                 U PyObject_GC_Del
                 U PyObject_GC_Track
                 U PyObject_GC_UnTrack
                 U PyObject_GenericGetAttr
                 U PyObject_GenericSetAttr
                 U PyObject_GetAttr
                 U PyObject_GetAttrString
                 U PyObject_GetBuffer
                 U PyObject_GetIter
                 U PyObject_IsInstance
                 U PyObject_IsSubclass
                 U PyObject_IsTrue
                 U PyObject_LengthHint
                 U PyObject_Malloc
                 U PyObject_Realloc
                 U PyObject_Repr
                 U PyObject_RichCompare
                 U PyObject_RichCompareBool
                 U PyObject_SelfIter
                 U PyObject_SetAttr
                 U PyObject_SetAttrString
                 U PyObject_Size
                 U PyObject_Str
                 U PyRange_Type
                 U PySeqIter_Type
                 U PySequence_Check
                 U PySequence_GetItem
                 U PySequence_InPlaceConcat
                 U PySet_Add
                 U PySet_New
                 U PySet_Type
                 U PySlice_New
                 U PySlice_Type
                 U PyStructSequence_InitType
                 U PyStructSequence_New
                 U PySuper_Type
                 U PySys_GetObject
                 U PyTraceBack_Type
                 U PyTuple_New
                 U PyTuple_Pack
                 U PyTuple_Type
                 U PyType_GetFlags
                 U PyType_IsSubtype
                 U PyType_Ready
                 U PyType_Type
                 U PyUnicode_AsUTF8
                 U PyUnicode_AsUnicode
                 U PyUnicode_Concat
                 U PyUnicode_DecodeUTF8
                 U PyUnicode_FindChar
                 U PyUnicode_Format
                 U PyUnicode_FromFormat
                 U PyUnicode_FromOrdinal
                 U PyUnicode_FromString
                 U PyUnicode_FromStringAndSize
                 U PyUnicode_InternInPlace
                 U PyUnicode_New
                 U PyUnicode_Substring
                 U PyUnicode_Type
                 U Py_BuildValue
                 U Py_CompileStringExFlags
                 U Py_Exit
                 U Py_GenericAlias
                 U Py_GenericAliasType
                 U _PyArg_NoKeywords
                 U _PyAsyncGenWrappedValue_Type
                 U _PyByteArray_empty_string
                 U _PyBytes_Resize
                 U _PyDict_NewPresized
                 U _PyErr_FormatFromCause
                 U _PyGen_FetchStopIterationValue
                 U _PyGen_SetStopIterationValue
                 U _PyImport_FixupExtensionObject
                 U _PyLong_New
                 U _PyObject_GC_Malloc
                 U _PyObject_GC_New
                 U _PyObject_GC_Resize
                 U _PyObject_HasLen
                 U _PyObject_New
                 U _PyRuntime
                 U _PySet_NextEntry
                 U _PyType_Lookup
                 U _PyUnicode_Ready
                 U _Py_Dealloc
                 U _Py_EllipsisObject
                 U _Py_FalseStruct
                 U _Py_NewReference
                 U _Py_NoneStruct
                 U _Py_NotImplementedStruct
                 U _Py_PackageContext
                 U _Py_TrueStruct
00000000000787f0 B __bss_start
                 U __cxa_atexit@LIBC
                 U __cxa_finalize@LIBC
                 U __errno@LIBC
                 U __register_atfork@LIBC
00000000000787f0 D _edata
00000000000796f8 B _end
                 U abort@LIBC
                 U dirname@LIBC
                 U dladdr@LIBC
                 U dlerror@LIBC
                 U dlopen@LIBC
                 U dlsym@LIBC
                 U fmod@LIBC
                 U getenv@LIBC
                 U getpid@LIBC
                 U gettimeofday@LIBC
                 U mbstowcs@LIBC
                 U memcmp@LIBC
                 U memcpy@LIBC
                 U memset@LIBC
                 U pow@LIBC
                 U printf@LIBC
                 U puts@LIBC
                 U snprintf@LIBC
                 U strcasecmp@LIBC
                 U strcat@LIBC
                 U strchr@LIBC
                 U strcmp@LIBC
                 U strcpy@LIBC
                 U strdup@LIBC
                 U strlen@LIBC
                 U strncmp@LIBC
                 U strncpy@LIBC
                 U strrchr@LIBC
                 U vsprintf@LIBC
                 U wcslen@LIBC
(venv) ~/python/out $ ldd nuitka_test.cpython-39.so
libdl.so
libm.so
libpython3.so
libc.so
(venv) ~/python/out $ mv nuitka_test.cpython-39.so nuitka_test.so
(venv) ~/python/out $ python
Python 3.9.6 (default, Jun 30 2021, 09:17:59)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nuitka_test
>>> exit()

@liukangcc
Copy link
Author

Differences between the two .so files

image

image

@kayhayen
Copy link
Member

I was also interested, what symbols the python binary exports. You know, in standard non-Windows configurations (there is't the reversed), Python does not load libpython, but provides the symbols itself. That way, when nuitka_test is loaded, the symbols come from there. I am having the suspect, that your Python is different in this regard.

Nuitka long ago did link extension modules against the Python shared library, however, there are Python things, manylinux comes to mind, where there is no shared Python library, and then it was understood, you are not required to link to it. Only the ldd table of ELF is the difference here, I do not consider the diff any relevant.

Let me know. If am correct, this command should be empty for you:

nm -gD `which python`

Which would be something to detect and handle by linking against the link library used by the binary. There should be libpython in your ldd output for the python binary then.

@liukangcc
Copy link
Author

liukangcc commented Jul 22, 2021

~ $ nm -gD `which python`
                 U Py_BytesMain
0000000000001d60 D __FINI_ARRAY__
0000000000001d50 D __INIT_ARRAY__
0000000000001d40 D __PREINIT_ARRAY__
0000000000002000 A __bss_start
                 U __cxa_atexit@LIBC
                 U __libc_init@LIBC
                 U __register_atfork@LIBC
0000000000002000 A _edata
0000000000002008 A _end
0000000000000680 T _start

This is very different from my output on the Ubuntu host.

@kayhayen
Copy link
Member

Yes, this is the root cause, and it links against a shared libpython, which does have the exports. I will try and add a detection of this into the linking parts, such that a loaded python DLL will be linked against for the extension modules too. With executables, unless --static-libpython=yes, that's done anyway. That way it won't be about the specific platform, but work for everybody who chooses to do this configuration, or not, should they ever change their mind.

@kayhayen kayhayen added the delayed This is waiting for something else to be done first. label Nov 3, 2021
@kayhayen
Copy link
Member

kayhayen commented Nov 3, 2021

I would need instructions how to set this up, then I can do this mayhaps. But I don't think I will have the time unless somebody provides funding.

@kayhayen kayhayen added the funding_wanted Will do it for customers: https://nuitka.net/pages/commercial.html label Nov 3, 2021
@kayhayen kayhayen added enhancement An improvement rather than a bug and removed needs_example User input needed funding_wanted Will do it for customers: https://nuitka.net/pages/commercial.html labels May 15, 2022
@kayhayen
Copy link
Member

Without feedback there is nothing I can do, if somebody wants to provide funding and see this implemented, let me know, otherwise this is delayed until such time.

@kayhayen kayhayen changed the title Nuitka in the Android Nuitka in specific Android environments May 15, 2022
@kayhayen kayhayen self-assigned this May 15, 2022
@kayhayen kayhayen removed the delayed This is waiting for something else to be done first. label Jan 15, 2023
@kayhayen
Copy link
Member

It seems Termux is working nowadays just fine.

@liukangcc
Copy link
Author

It seems Termux is working nowadays just fine.

Sounds great! I'll try it

@Nuitka Nuitka locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement An improvement rather than a bug
Projects
None yet
Development

No branches or pull requests

2 participants