From f266e6ec625e272627acaca79ab21257d664ac01 Mon Sep 17 00:00:00 2001 From: rango Date: Thu, 30 Apr 2026 10:00:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=20Windows=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=93=BE=E6=8E=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 替换 ws2_32.lib 等库为 msvcrt.lib、kernel32.lib 等完整的 CRT 和系统库 - 添加 oldnames.lib、gdi32.lib、winspool.lib 等必要的 Windows API 库 - 保留 ws2_32.lib 并添加 uuid.lib、odbc32.lib 等数据库相关库 - 为编译器添加 /MD 参数以使用动态多线程 CRT - 移除 ZEND_ENABLE_STATIC_TSRMLS_CACHE 宏定义以避免静态缓存冲突 --- src/Php/CompilerBase.php | 26 +++++++++++++++++--------- src/Php/Translator.php | 1 - 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 2bb7f5b5..bdd4238f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2363,15 +2363,22 @@ class CompilerBase extends \PhpAot\Core\Translator } } -// // 添加 Windows 系统库(PHP 嵌入模式必需) -// $list[] = 'ws2_32.lib'; // Winsock -// $list[] = 'advapi32.lib'; // 高级 API -// $list[] = 'user32.lib'; // 用户界面 -// $list[] = 'shell32.lib'; // Shell API -// $list[] = 'ole32.lib'; // OLE -// $list[] = 'oleaut32.lib'; // OLE Automation -// $list[] = 'crypt32.lib'; // 加密 API - + // 添加 CRT 和系统库(解决 LNK2019 错误) + $list[] = 'msvcrt.lib'; // C 运行时库(动态) + $list[] = 'oldnames.lib'; // 旧名称兼容库 + $list[] = 'kernel32.lib'; // Windows 核心 API + $list[] = 'user32.lib'; // 用户界面 + $list[] = 'gdi32.lib'; // GDI + $list[] = 'winspool.lib'; // 打印池 + $list[] = 'comdlg32.lib'; // 通用对话框 + $list[] = 'advapi32.lib'; // 高级 API + $list[] = 'shell32.lib'; // Shell API + $list[] = 'ole32.lib'; // OLE + $list[] = 'oleaut32.lib'; // OLE Automation + $list[] = 'uuid.lib'; // UUID + $list[] = 'odbc32.lib'; // ODBC + $list[] = 'odbccp32.lib'; // ODBC CP + $list[] = 'ws2_32.lib'; // Winsock } $out = ''; @@ -2471,6 +2478,7 @@ class CompilerBase extends \PhpAot\Core\Translator $cmd .= ' ' . $this->ldflags; } } else { + // 编译时使用动态多线程 CRT(与 PHP SDK 一致) $cmd .= ' /MD'; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d7ca7b3c..1044a5e4 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -680,7 +680,6 @@ CODE; if ($this->isPhpZts) { $cmd .= ' /DZTS'; } - $cmd .= ' /DZEND_ENABLE_STATIC_TSRMLS_CACHE'; $cmd .= ' /Od /W3 /wd4244 /wd4146 /nologo'; } } else {