如何在 Windows 上为 PHP7.0 编译 PECL 扩展 win32service

How to compile PECL extension win32service for PHP7.0 on Windows

我试图从 https://pecl.php.net/package/win32service

编译 pecl 扩展 win32service

在撰写本文时,上面的 pecl 页面仅提供 PHP5.5 和 PHP5.6 的版本。所以我尝试自己编译它。由于 PHP7.0 在我的环境中构建良好,我收到了一些 linker 错误。

Creating library C:\php-sdk\phpdev\vc14\x64\php-7.0.14-src\x64\Release_TS\php_win32service.lib and object C:\php-sdk\phpdev\vc14\x64\php-7.0.14-src\x64\Release_TS\php_win32service.exp
win32service.obj : error LNK2019: unresolved external symbol Z_TYPE_PP referenced in function svc_thread_proc
win32service.obj : error LNK2019: unresolved external symbol Z_STRVAL_PP referenced in function svc_thread_proc
win32service.obj : error LNK2019: unresolved external symbol Z_STRLEN_PP referenced in function svc_thread_proc
win32service.obj : error LNK2019: unresolved external symbol Z_LVAL_PP referenced in function svc_thread_proc
C:\php-sdk\phpdev\vc14\x64\php-7.0.14-src\x64\Release_TS\php_win32service.dll : fatal error LNK1120: 4 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe"' : return code '0x460'
Stop.

使用的配置(Windows 7、x64、TS、VC14、PHP7.0.14):

configure --disable-all --enable-cli --enable-win32service=shared

如何构建该扩展或如何修复代码以 link 正常?

我从维护者那里收到了一条说明,指出了根本原因所在的某个方向。非常感谢理查德。

扩展名必须从 PHP (5.x.x) 调整为 PHPNG (7.x.x)。 内部结构已更改,宏(例如 Z_TYPE_PP)已不复存在。

文档 https://wiki.php.net/internals/engine/objects 说:

The type of zval may be read using Z_TYPE() or Z_TYPE_P() macros, type flags using Z_TYPE_FLAGS() or Z_TYPE_FLAGS_P(), the combination of type and flags – Z_TYPE_INFO() or Z_TYPE_INFO_P(). PHPNG doesn't work with pointers to pointers to zval and it doesn't provide macros with _PP() suffix anymore (like Z_TYPE_PP).

所以这意味着扩展代码必须是 refactored/rewritten 因为宏已经消失,正如您在 PHP 代码本身中看到的那样:

PHP5.6: http://lxr.php.net/source/xref/PHP-5.6/Zend/zend_operators.h#491

PHP7.0: http://lxr.php.net/source/xref/PHP-7.0/Zend/zend_types.h#337

更新: 自从我的问题以来,该扩展中已经做了很多工作。已经有几个工作发布,甚至 dll 被上传到 pecl 页面: https://pecl.php.net/package/win32service

我正在为 PHP-7.0 和 PHP-7.1 构建 php_win32service: https://github.com/fawno/pecl-system-win32service/releases https://github.com/alpha/win32service/releases

更新: macintoshplus 正在努力更新 https://github.com/InExtenso/win32service 中的扩展 他需要帮助才能成为包裹的维护者: https://github.com/InExtenso/win32service/issues/4