Windows 中编译 PHP5.4 + xdebug

本文介绍了在使用VS2005编译PHP扩展模块时遇到的错误,包括如何修复errorC2466、strnlen定义DLL导入函数错误以及calendar.c和jewish.c的编码问题。通过简单的步骤,可以有效解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考 http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html

1.  error C2466: cannot allocate an array of constant size 0
用C/C++写PHP的扩展模块,如果VS2005编译,可能会出现下面的错误:
<VS2005安装目录>\VC\include\sys/stat.inl(44) : error C2466: 不能分配常量大小为 0 的数组  
,出现这种情况时,只需在 <VS2005安装目录>\vc\include\malloc.h 文件中找到:
#define _STATIC_ASSERT(expr) typedef char __static_assert_t[ (expr) ]  
 
并改成:
#ifdef PHP_WIN32  
#define _STATIC_ASSERT(expr) typedef char __static_assert_t[ (expr)?(expr):1 ]  
#else  
#define _STATIC_ASSERT(expr) typedef char __static_assert_t[ (expr) ]  
#endif  
就可以了。

单独编译 pdo:

打开 VS2005 命令行工具

1)执行命令cscript /nologo configure.js --enable-pdo
php error C2491: 'strnlen' : definition of dllimport function 
https://bugs.php.net/bug.php?id=47787
Description:
------------
Building 5.2.9 with VC++ 2005 results in the error:
main\spprintf.c(184) : error C2491: 'strnlen' : definition of dllimport function not allowed
This appears to be due to the change here: http://cvs.php.net/viewvc.cgi/php-src/main/spprintf.c?r1=1.25.2.2.2.14&r2=1.25.2.2.2.15
The issue is resolved by adding:
#define HAVE_STRNLEN 1
to win32/build/config.w32.h.in

2)ext\dom\php_dom.h(33) : fatal error C1083: Cannot open include file:  'libxml/parser.h': No such file or directory
修改 config 命令:cscript /nologo configure.js --enable-pdo --without-libxml

3)ext\calendar\jewish.c(324) : error C2001: newline in constant
关于 calendar.c 和 jewish.c 的编码问题:
这两个文件使用的是 ANSI 编码,包含有一些西文的特殊字符,GBK 字符集中不存在。
可用 editplus 打开,编码选择:West European (Windows),另存为 UTF-8。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值