项目

一般

简介

Nuitka » nuitka编译报错排查.txt

ly w, 2025-07-22 10:16

 
1. 报错:nuitka GNSS_start.py
Nuitka-Options: Used command line options:
Nuitka-Options: GNSS_start.py
Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure that is intended.
Nuitka: Starting Python compilation with:
Nuitka: Version '2.7.12' on Python 3.8 (flavor 'Debian Python') commercial grade 'not installed'.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka-Scons: Backend C compiler: gcc (gcc 9).
Nuitka-Scons: Backend C linking with 6 files (no progress information available for this stage).
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.
FATAL: Error, the C compiler 'gcc' crashed with segfault. Consider upgrading it or using '--clang' option.
scons: *** [/root/GNSS_emb/GNSS_start.bin] Explicit exit, status 1
FATAL: Failed unexpectedly in Scons C backend compilation.
Nuitka:WARNING: Complex topic! More information can be found at https://nuitka.net/info/scons-backend-failure.html
Nuitka-Reports: Compilation crash report written to file 'nuitka-crash-report.xml'.

2. vim nuitka-crash-report.xml
<?xml version='1.0' encoding='utf8'?>
<nuitka-compilation-report nuitka_version="2.7.12" nuitka_commercial_version="not installed" mode="accelerated" completion="error exit message (1)" exit_message="Failed unexpectedly in Scons C backend compilation.">
<scons_error_reports>
<scons_error_report>
<command>gcc -o "/root/GNSS_emb/GNSS_start.bin" -flto=8 -fuse-linker-plugin -fpartial-inlining -freorder-functions -O2 -s -z noexecstack -Xlinker -export-dynamic -rdynamic -Wl,-rpath=/usr/lib -Wl,-R,'/usr/lib' -Wl,--disable-new-dtags -Wl,-b -Wl,binary -Wl,./__constants.bin -Wl,-b -Wl,elf64-littleaarch64 -Wl,-defsym -Wl,constant_bin_data=_binary_____constants_bin_start @"./@link_input.txt" -L/usr/lib -ldl -lm "/usr/lib/python3.8/config-3.8-aarch64-linux-gnu/libpython3.8-pic.a" -lz -lm -lutil -lpthread -lexpat</command>
<stderr>
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]compilation terminated.
</stderr>

3. 设置nuitka打印完整编译命令
nuitka --show-scons --show-progress GNSS_start.py
报错:
Nuitka-Scons: Backend C linking with 6 files (no progress information available for this stage).
gcc -o /root/GNSS_emb/GNSS_start.bin -flto=8 -fuse-linker-plugin -fpartial-inlining -freorder-functions -O2 -s -z noexecstack -Xlinker -export-dynamic -rdynamic -Wl,-rpath=/usr/lib -Wl,-R,'/usr/lib' -Wl,--disable-new-dtags -Wl,-b -Wl,binary -Wl,./__constants.bin -Wl,-b -Wl,elf64-littleaarch64 -Wl,-defsym -Wl,constant_bin_data=_binary_____constants_bin_start @"./@link_input.txt" -L/usr/lib -ldl -lm /usr/lib/python3.8/config-3.8-aarch64-linux-gnu/libpython3.8-pic.a -lz -lm -lutil -lpthread -lexpat
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.
FATAL: Error, the C compiler 'gcc' crashed with segfault. Consider upgrading it or using '--clang' option.
scons: *** [/root/GNSS_emb/GNSS_start.bin] Explicit exit, status 1
scons: internal stack trace:
File "/usr/local/lib/python3.8/dist-packages/nuitka/build/inline_copy/lib/scons-3.1.2/SCons/Job.py", line 258, in run
task.execute()
File "/usr/local/lib/python3.8/dist-packages/nuitka/build/inline_copy/lib/scons-3.1.2/SCons/Script/Main.py", line 206, in execute
SCons.Taskmaster.OutOfDateTask.execute(self)
File "/usr/local/lib/python3.8/dist-packages/nuitka/build/inline_copy/lib/scons-3.1.2/SCons/Taskmaster.py", line 261, in execute
raise SCons.Errors.ExplicitExit(self.targets[0], exc_value.code)
scons: building terminated because of errors.
FATAL: Failed unexpectedly in Scons C backend compilation.
Nuitka:WARNING: Complex topic! More information can be found at https://nuitka.net/info/scons-backend-failure.html
Nuitka-Reports: Compilation crash report written to file 'nuitka-crash-report.xml'.

4. 手动执行编译命令(Nuitka 用 @"./@link_input.txt" 这种方式把所有要链接的对象文件列表放在一个文本文件里,而不是直接写在命令行上)
cd GNSS_start.build/(@link_input.txt在当前目录下,如果从来没有相应的build文件夹,可执行nuitka GNSS_start.py或nuitka --generate-c-only GNSS_start.py)
gcc -o /root/GNSS_emb/GNSS_start.bin -flto=8 -fuse-linker-plugin -fpartial-inlining -freorder-functions -O2 -s -z noexecstack -Xlinker -export-dynamic -rdynamic -Wl,-rpath=/usr/lib -Wl,-R,'/usr/lib' -Wl,--disable-new-dtags -Wl,-b -Wl,binary -Wl,./__constants.bin -Wl,-b -Wl,elf64-littleaarch64 -Wl,-defsym -Wl,constant_bin_data=_binary_____constants_bin_start @"./@link_input.txt" -L/usr/lib -ldl -lm /usr/lib/python3.8/config-3.8-aarch64-linux-gnu/libpython3.8-pic.a -lz -lm -lutil -lpthread -lexpat
报错:
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.

5. 对比编译正确的命令:
nuitka --show-scons --show-progress GNSS_start.py --lto=no
gcc -o /root/GNSS_emb/GNSS_start.bin -fno-lto -s -z noexecstack -Xlinker -export-dynamic -rdynamic -Wl,-rpath=/usr/lib -Wl,-R,'/usr/lib' -Wl,--disable-new-dtags @"./@link_input.txt" -L/usr/lib -ldl -lm /usr/lib/python3.8/config-3.8-aarch64-linux-gnu/libpython3.8-pic.a -lz -lm -lutil -lpthread -lexpat

6. 结论
--lto影响链接成exe,所以应该使用 --lto=no 选项去掉lto优化,完整命令应该是:
nuitka GNSS_start.py --lto=no
(2-2/3)