|
5 | 5 | namespace SPC\builder; |
6 | 6 |
|
7 | 7 | use SPC\exception\EnvironmentException; |
| 8 | +use SPC\exception\FileSystemException; |
8 | 9 | use SPC\exception\SPCException; |
9 | 10 | use SPC\exception\ValidationException; |
10 | 11 | use SPC\exception\WrongUsageException; |
11 | 12 | use SPC\store\Config; |
12 | 13 | use SPC\store\FileSystem; |
| 14 | +use SPC\toolchain\ClangNativeToolchain; |
| 15 | +use SPC\toolchain\GccNativeToolchain; |
13 | 16 | use SPC\toolchain\ToolchainManager; |
14 | 17 | use SPC\toolchain\ZigToolchain; |
15 | 18 | use SPC\util\SPCConfigUtil; |
@@ -418,8 +421,24 @@ public function buildUnixShared(): void |
418 | 421 | 'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"), |
419 | 422 | 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, |
420 | 423 | ]; |
421 | | - if (ToolchainManager::getToolchainClass() === ZigToolchain::class && SPCTarget::getTargetOS() === 'Linux') { |
422 | | - $env['SPC_COMPILER_EXTRA'] = '-lstdc++'; |
| 424 | + if (str_contains($env['LIBS'], '-lstdc++') && SPCTarget::getTargetOS() === 'Linux') { |
| 425 | + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { |
| 426 | + $env['SPC_COMPILER_EXTRA'] = '-lstdc++'; |
| 427 | + } elseif (ToolchainManager::getToolchainClass() === GccNativeToolchain::class || ToolchainManager::getToolchainClass() === ClangNativeToolchain::class) { |
| 428 | + try { |
| 429 | + $content = FileSystem::readFile($this->source_dir . '/config.m4'); |
| 430 | + if ($content && !str_contains($content, 'PHP_ADD_LIBRARY(stdc++')) { |
| 431 | + $pattern = '/(PHP_NEW_EXTENSION\(' . $this->name . ',.*\))/m'; |
| 432 | + $replacement = "$1\nPHP_ADD_LIBRARY(stdc++, 1, " . strtoupper($this->name) . '_SHARED_LIBADD)'; |
| 433 | + FileSystem::replaceFileRegex( |
| 434 | + $this->source_dir . '/config.m4', |
| 435 | + $pattern, |
| 436 | + $replacement |
| 437 | + ); |
| 438 | + } |
| 439 | + } catch (FileSystemException) { |
| 440 | + } |
| 441 | + } |
423 | 442 | } |
424 | 443 |
|
425 | 444 | if ($this->patchBeforeSharedPhpize()) { |
|
0 commit comments