头文件和目标文件数组需要去重,不然编译会提示重复定义 #40

Closed
NathanFreeman wants to merge 1 commits from remove-duplicates into master
  1. 10
      src/Translator.php
  2. 4
      src/compiler.php

@ -1735,10 +1735,12 @@ CODE;
public function genIncludeHeaderFiles(): string public function genIncludeHeaderFiles(): string
{ {
$headers = array_merge($this->globalHeaders, [ $headers = array_unique(array_merge(
"php_{$this->targetName}_func_decl.h", $this->globalHeaders,
"php_{$this->targetName}_data_decl.h", ["php_{$this->targetName}_func_decl.h", "php_{$this->targetName}_data_decl.h"],
], $this->localHeaders); $this->localHeaders
));
$lines = []; $lines = [];
foreach ($headers as $header) { foreach ($headers as $header) {
$lines[] = '#include <' . $header . '>'; $lines[] = '#include <' . $header . '>';

@ -31,8 +31,8 @@ function main(int $argc, array $argv): void
return; return;
} }
// 编译所有 C++ 文件 // 去重和编译所有 C++ 文件
$objectFiles = $translator->compile($sourceFiles); $objectFiles = array_unique($translator->compile($sourceFiles));
// 连接所有目标文件,生成可执行文件 // 连接所有目标文件,生成可执行文件
$binaryFile = $translator->build($objectFiles); $binaryFile = $translator->build($objectFiles);
// 如果指定了 --run / -r,编译完成后立即执行 // 如果指定了 --run / -r,编译完成后立即执行

Loading…
Cancel
Save