<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>潘锦的空间 &#187; win7</title>
	<atom:link href="https://www.phppan.com/tag/win7/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.phppan.com</link>
	<description>SaaS SaaS架构 团队管理 技术管理 技术架构 PHP 内核 扩展 项目管理</description>
	<lastBuildDate>Sun, 12 Apr 2026 03:47:23 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>win7下用vs2008开发PHP扩展</title>
		<link>https://www.phppan.com/2010/10/win7-vs2008-php-extension/</link>
		<comments>https://www.phppan.com/2010/10/win7-vs2008-php-extension/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 12:49:48 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP扩展]]></category>
		<category><![CDATA[vs2008]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=1033</guid>
		<description><![CDATA[win7下用vs2008开发PHP扩展 由于在win7下安装vc6比较麻烦，一直没有安装成功，只能改用vs20 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>win7下用vs2008开发PHP扩展<br />
由于在win7下安装vc6比较麻烦，一直没有安装成功，只能改用vs2008.<br />
由于要编译PHP扩展，于是做了一个简单PHP扩展开发的DEMO</p>
<p>环境：win7 + vs2008 + cygwin + php5.3.1 + xampp1.7.3<br />
生成过程如下：<br />
1、环境配置，安装cygwin,这个在生成PHP扩展的框架时有用到,我的安装目录为c:\cygwin<br />
2、安装xampp1.7.3，下载地址可以google下<br />
3、下载php5.3.1，下载地址：http://cn.php.net/get/php-5.3.1.tar.gz/from/cn2.php.net/mirror，解压到目录PHPHOME(我的是在D:\project\c\php-5.3.1)<br />
4、安装vs2008，这个时间会久一些<br />
5、如果以上的一切都安装好了，那么转第6步，我们开始开发扩展martin（这只是一个名称而已）<br />
<br />6、在命令行中，cd进入PHPHOME/ext/目录，输入php.exe ext_skel_win32.php &#8211;extname=martin，此时在ext目录下会生成martin文件夹及在此文件夹下与扩展相关的文件，包括php_martin.h,martin.c文件等。<br />
如果php.exe所在目录没有加到PATH中，请在php.exe前面加程序的完整路径<br />
<br />7、打开vs2008,新建基于已有文件的项目,选择VC++,选择文件所在目录，输入项目名称php_martin, 下一步，在Project type:中选择 DLL project,next直到完成。<br />
8、修改源码，<br />
   打开php_martin.h文件，找到PHP_FUNCTION(confirm_martin_compiled);在其下面增加一个扩展函数声明：PHP_FUNCTION(martin_echo);<br />
   打开martin.c文件，找到zend_function_entry martin_functions[],在其元素中添加 PHP_FE(martin_echo,	NULL)<br />
   在martin.c文件中添加如下代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">   PHP_FUNCTION<span style="color: #009900;">&#40;</span>martin_echo<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>arg <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> arg_len<span style="color: #339933;">,</span> len<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>strg<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zend_parse_parameters<span style="color: #009900;">&#40;</span>ZEND_NUM_ARGS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> TSRMLS_CC<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;s&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>arg<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>arg_len<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> FAILURE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	len <span style="color: #339933;">=</span> spprintf<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>strg<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;This is %s's extension.the input string is %s.&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;martin&quot;</span><span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	RETURN_STRINGL<span style="color: #009900;">&#40;</span>strg<span style="color: #339933;">,</span> len<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>9、按F7 build此项目，此时会有文件找不到报错，此乃php部分源码没有包含的原因，右键项目属性，选择【Configuration Properties】-> 【C/C++】-> 【General】-> 【Additional Include Directories】，将源码根目录，main目录，TSRM目录，Zend目录添加到此处我的是（&#8221;D:\project\c\php-5.3.1&#8243;;&#8221;D:\project\c\php-5.3.1\main&#8221;;&#8221;D:\project\c\php-5.3.1\TSRM&#8221;;&#8221;D:\project\c\php-5.3.1\Zend&#8221;）<br />
10、继续build，此时可能会显示zend_config.h文件找不到，此时为部分宏没有定义,解决方案：选择项目属性，选择【Configuration Properties】-> 【C/C++】-> 【Preprocessor】-> 【Preprocessor Definitions】，在此处理添加 ZEND_DEBUG=0;COMPILE_DL_MARTIN;ZTS;ZEND_WIN32;PHP_WIN32;HAVE_MARTIN=1<br />
对于不同的扩展可以将COMPILE_DL_MARTIN和HAVE_MARTIN中的MARTIN替换成你的扩展名</p>
<p>11、继续build,此时可能会显示../main/config.w32.h没有找到，google了半天，所说在php5.2.9的源码中有此文件存在（此文件应该是某个环节生成的，没搞清楚），于是下载5.2.9，将此文件放到main目录下</p>
<p>12、继续build，此时可能会显示fatal error LNK1120，解决方案：打开项目属性，选择【Configuration Properties】-> 【Linker】->【Input】->【Additional Dependencies】，在此处添加php5ts.lib，另外需要在【Tools】->【Options】->【Projects and Solutions】->【VC++ Directories】，在【Show directories for:】下拉中，选择Librafy files，将php5ts.lib所在的路径添加进来，此文件存在于 二进制版本的dev/lib目录下。</p>
<p>13、右键solution属性，将Configuration选择为Release<br />
14、build，在ext\martin\Release下会有生成你一个以你的项目名为名称的dll文件(我的为php_martin.dll)<br />
15、将php_martin.dll文件拷贝到机器中运行的php所在的ext目录，修改php.ini文件，添加一行：extension=php_martin.dll，重启apache，<br />
16，运行一个包含了 echo martin_echo(&#8220;phppan.com&#8221;);语句的php文件，可以看到有输出This is martin&#8217;s extension.the input string is phppan.com.</p>
<p>如果你在启动apache中有报错为:<br />
PHP Warning:  PHP Startup: martin: Unable to initialize module\nModule compiled with build ID=API20090626,TS\nPHP    compiled with build ID=API20090626,TS,VC6\nThese options need to match\n in Unknown on line 0<br />
<br />
<b>Warning</b>:  PHP Startup: martin: Unable to initialize module<br />
Module compiled with build ID=API20090626,TS<br />
PHP    compiled with build ID=API20090626,TS,VC6<br />
These options need to match<br />
 in <b>Unknown</b> on line <b>0</b><br />
<strong>你需要在main/config.w32.h中添加如下语句<br />
#define PHP_COMPILER_ID &#8220;VC6&#8243;</strong><br />
此处来源于：<a href="http://hi.baidu.com/zhangsilly/blog/item/7a3c7f73f7dcad108701b082.html">PHP5.3系列设置编译器ID（build ID）</a></p>
<p>&#8211;EOF&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2010/10/win7-vs2008-php-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
