fix(link): _merged.obj 存在时仍链接 include 的 .obj

_merged.obj 只合并非 include 模块;此前命中该分支后跳过 include 的 .obj,导致 argparse.print_help 等符号未链接进 exe。
This commit is contained in:
TermiNexus committed 2026-10-18 22:13:50 +08:00
1 parent 2e80424d67
commit d4fc66fe3c
1 file changed
+14 -8
+14 -8
View File
@@ -4913,15 +4913,21 @@ class Phase2Translator:
"""将 active_sha1s 对应的 .obj 文件和 includes 库文件链接为可执行文件"""
obj_files = []
merged_obj = os.path.join(self.output_dir, '_merged.obj')
if _CachedIsFile(merged_obj):
has_merged: bool = _CachedIsFile(merged_obj)
if has_merged:
# _merged.obj 只合并了非 include 模块,include 的 .obj 仍需单独链接
obj_files.append(merged_obj)
else:
for root, dirs, files in os.walk(self.output_dir):
for file in files:
if file.endswith('.obj'):
sha1 = file[:-4]
if sha1 in active_sha1s and sha1 not in self._include_sha1s:
obj_files.append(os.path.join(root, file))
for root, dirs, files in os.walk(self.output_dir):
for file in files:
if file.endswith('.obj'):
sha1 = file[:-4]
if sha1 not in active_sha1s:
continue
if has_merged and sha1 not in self._include_sha1s:
continue
if not has_merged and sha1 in self._include_sha1s:
continue
obj_files.append(os.path.join(root, file))
if not obj_files and not self.extra_link_files:
_vlog().info("[链接] 无文件可链接")