头文件和目标文件需要去重,不然会出现重复定义

pull/40/head
NathanFreeman 4 weeks ago
parent 2a1a11d1b5
commit 6242f3479a
  1. 10
      src/Translator.php
  2. 4
      src/compiler.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 . '>';

@ -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,编译完成后立即执行

Loading…
Cancel
Save