Nuitka生成C代码转WASM遇编译错误,求解决方案
Nuitka转C代码后用emcc编译为WASM的问题
操作背景
尝试通过Nuitka将Python代码编译为C代码,再用emcc将生成的C代码编译为WASM。已执行命令:
python -m nuitka --standalone --output-dir=output HelloWorld.py
成功从HelloWorld.py生成C代码,输出目录下包含build和dist文件夹,其中build文件夹内文件如下:
__constants.bin __constants.c __constants.const __constants.h __constants.o __helpers.c __helpers.h __helpers.o __loader.c __loader.o module.__main__.c module.__main__.const
build下的static_src文件夹包含:
CompiledFunctionType.c CompiledFunctionType.o MainProgram.c MainProgram.o
遇到的编译问题
本人对C语言不熟悉,不清楚如何将这些分散的文件通过emcc编译为WASM。尝试单独编译单个文件:
emcc module.__main__.c -o module.__main__.wasm
因缺少Nuitka相关头文件(如nuitka/prelude.h和patchlevel.h)报错;添加头文件路径后,又出现如下错误:
/Users/gui/.pyenv/versions/3.10.0/include/python3.10/pyport.h:746:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." 746 | #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
已确认Python和编译器均为64位,仍无法解决该错误。
求助内容
- 求上述LONG_BIT错误的解决方案
- 确认「Nuitka转C再转WASM」的方案是否可行
- 提供针对性的编译建议
附加信息
- Python版本:3.10.0
- Nuitka版本:1.7.1
- Nuitka编译输出:
Nuitka-Options:INFO: Used command line options: --standalone --output-dir=output HelloWorld.py Nuitka:INFO: Starting Python compilation with Nuitka '1.7.1' on Python '3.10' commercial grade 'not installed'. 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 compilation via Scons. Nuitka-Scons:INFO: Backend C compiler: /usr/bin/clang (clang). Nuitka-Scons:INFO: Backend linking program with 6 files (no progress information available for this stage). Nuitka-Scons:INFO: Compiled 6 C files using ccache. Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache hit': 6 Nuitka:INFO: Keeping build directory 'output/HelloWorld.build'. Nuitka:INFO: Created binary that runs on macOS 12.4 (arm64) or higher. Nuitka:INFO: Successfully created 'output/HelloWorld.dist/HelloWorld.bin'.
内容的提问来源于stack exchange,提问作者guibvieira
相关产品推荐
相关产品推荐

