diff --git a/src/Translator.php b/src/Translator.php index 542d0278..68041590 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -1735,10 +1735,12 @@ CODE; public function genIncludeHeaderFiles(): string { - $headers = array_merge($this->globalHeaders, [ - "php_{$this->targetName}_func_decl.h", - "php_{$this->targetName}_data_decl.h", - ], $this->localHeaders); + $headers = array_unique(array_merge( + $this->globalHeaders, + ["php_{$this->targetName}_func_decl.h", "php_{$this->targetName}_data_decl.h"], + $this->localHeaders + )); + $lines = []; foreach ($headers as $header) { $lines[] = '#include <' . $header . '>'; diff --git a/src/compiler.php b/src/compiler.php index ce7977ae..5e69ea66 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -31,8 +31,8 @@ function main(int $argc, array $argv): void return; } - // 编译所有 C++ 文件 - $objectFiles = $translator->compile($sourceFiles); + // 去重和编译所有 C++ 文件 + $objectFiles = array_unique($translator->compile($sourceFiles)); // 连接所有目标文件,生成可执行文件 $binaryFile = $translator->build($objectFiles); // 如果指定了 --run / -r,编译完成后立即执行