[PHP] Compile an extension on Windows
https://wiki.php.net/internals/windows/stepbystepbuild
http://blog.benoitblanchon.fr/build-php-extension-on-windows/
https://wiki.php.net/internals/windows/libs
[PHP] Compile an extension on Windows
20 Jan 2015 PHP
I recently wrote a PHP extension and while the documentation is very clear on how to build it on Linux, there is not so much information on how to compile an extension on Windows.
This article explains how to build a PHP extension with Visual Studio.
Requirements
This guide assumes that you wrote a "Hello World" PHP extension as described here and that you compiled it successfully on Linux.
To build your extension on Windows, you'll need:
- Visual Studio (I tested with Visual Studio 2013 Update 4)
- The PHP source code (I tested with PHP 5.5.20)
In the rest of this article, I assume that:
- The PHP source code is located in
C:\php-src
- Your "Hello World" extension source code is located in
C:\MyPhpExtensions\hello
The build process on Linux
You should already familiar with the process, but here is a reminder:
- Install
php-devel
package - Run
phpize
to generate theconfigure
script fromconfig.m4
. - Run
./configure --enable-hello
to generate theMakefile
- Run
make
to build the extension
From config.m4
to config.w32
On Windows, config.m4
is replaced by config.w32
which has a different format.
Migrating from config.m4
to config.w32
is really straighforward, you just need to translate the automake syntax to JavaScript.
Here is a minimalist example:
ARG_ENABLE("hello", "Hello World support", "no");
if (PHP_HELLO != "no") {
EXTENSION("hello", "php_hello.c", true);
}
Don't forget the true
as the third argument of the EXTENSION
function, it means that we want a DLL instead of a static library.
If you need more information on the syntax, look at the existing config.w32
in the PHP source code.
From phpize
to buildconf.bat
On Windows, you don't call phpize
but instead you call buildconf.bat
.
Open a Visual Studio developer command prompt (either 64 or 32 bit), and run
cd C:\php-src
buildconf.bat --add-modules-dir=C:\MyPhpExtensions
buildconf.bat
will scan each subfolder of C:\MyPhpExtensions
looking for config.w32
files.
It will then generate a configure.bat
.
From ./configure
to configure.bat
The configure
script that you used on Linux did exactly what you wanted: it just built the extension.
But on Windows it's different because the script is designed to build PHP itself.
You need to add command line options to configure.bat
to build the minimum number of stuff, so as to make sure that you wont have to solve dependencies to external libraries
cd C:\php-src
configure.bat --disable-all --enable-cli --enable-hello
--disable-all
is a shortcut for all the --disable-xxx
and --without-xxx
flags, --enable-cli
enables back the PHP command line interface (ie php.exe
) and --enable-hello
enables your "Hello World" extension.
By default, this will create a "Thread Safe" build.
If you want a non thread safe build, just add --disable-zts
to the command line.
From Make
to NMake
configure.bat
generated a Makefile
for the Microsoft version of Make
.
To start the build, just run:
nmake
This will build your PHP extension, as well as php.exe
.
This is handy because you'll need a php.exe
that matches the configuration of your extension.
Indeed, in order to be loaded in PHP, your extension must match the PHP build in term of:
- word size (32 or 64 bits)
- thread safety (TS build or NTS build)
- compiler version (VS9, VS11 etc.)
If you really don't need to build php.exe
, you can use this command line:
nmake php_hello.dll
Thousands of warnings
During the compilation of PHP, the compiler issues a lot of warnings.
If you want to prevent this, just add the following file to c:\php-src\win32\build\config.w32
:
ADD_FLAG('CFLAGS', ' /wd4005 /wd4267 /wd4244 ');
ADD_FLAG('CFLAGS_BD_ZEND', ' /wd4018 /wd4101 /wd4090 /wd4273 ');
ADD_FLAG('CFLAGS_BD_MAIN', ' /wd4018 /wd4090 ');
ADD_FLAG('CFLAGS_BD_MAIN_STREAMS', ' /wd4013 ');
DEFINE('RC', '$(RC) /nologo /d _USING_V110_SDK71_');
Also, add the following line to C:\php-src\ext\standard\config.w32
:
ADD_FLAG('CFLAGS_BD_EXT_STANDARD', ' /wd4047 /wd4018 ');
And finally, add this line to C:\php-src\sapi\cli\config.w32
:
ADD_FLAG('CFLAGS_BD_SAPI_CLI', ' /wd4018 ');
Bonus: best resources on PHP extension development
- Extension Writing Part I: Introduction to PHP and Zend
- Extension Writing Part II: Parameters, Arrays, and ZVALs
- Extension Writing Part II: Parameters, Arrays, and ZVALs [continued]
- Extension Writing Part III: Resources
- Wrapping C++ Classes in a PHP Extension
- PHP Extension Writing
- PHP Extensions Made Eldrich: Working with the API – the PHP C API
- PHP Extensions Made Eldrich: Classes
- Build your own PHP on Windows
- PHP Internals Book
- Zend API: Hacking the Core of PHP
[PHP] Compile an extension on Windows的更多相关文章
- Jenkins邮件扩展(Email Extension插件 Windows环境)
1.Jenkins ver. 2.107.3版本自带Email Extension插件启动后即可看到系统设置里的 Extended E-mail Notification ,如果没有请安装 2.安装过 ...
- build-qt.sh(Cross compile in Linux for Windows)
#!/bin/bash set -e MINGW=${MINGW:-${ARCH:-x86_64}-w64-mingw32} PREFIX=${PREFIX:-usr} WORKSPACE=${WOR ...
- windows 10 上源码编译OpenCV并支持CUDA | compile opencv with CUDA support on windows 10
本文首发于个人博客https://kezunlin.me/post/6580691f/,欢迎阅读! compile opencv with CUDA support on windows 10 Ser ...
- Windows下apache php wordpress配置
2. Use notepad to open httpd.conf config file. Make use the line "LoadModule rewrite_module mod ...
- 一步步实现windows版ijkplayer系列文章之六——SDL2源码分析之OpenGL ES在windows上的渲染过程
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...
- A Great List of Windows Tools
Windows is an extremely effective and a an efficient operating system. Like any other operating syst ...
- Windows 7操作系统下PHP 7的安装与配置(图文详解)
前提博客 Windows 7操作系统下Apache的安装与配置(图文详解) 从官网下载 PHP的官网 http://www.php.net/ 特意,新建这么一个目录 ...
- Windows phone应用开发[20]-禁止Pivot手势
相比Ios 和Android. Windows Phone 控件库中多了两个比较特殊的空间Pivot 枢轴和Panamera 全景视图控件.在基于枢轴控件Pivot中我们经常会碰到一些比较特殊应用场景 ...
- 将Win8.1/WP8.1应用迁移到Universal Windows Platform
在上一篇在VS2015 RC打开CTP中创建的工程,我们介绍了怎么在RC中打开CTP中创建的Universal 工程,这一篇我们来讲下怎么将Windows 8.1/WP8.1的应用迁移到Univers ...
随机推荐
- This kernel requires an x86-64 CPU, but only detected an i686 CPU.
为了运行一款软件,我也是拼了.彻底的玩了一次,因为A需要B,我去下载B,结果B又需要C,我去下载C,结果……怎一个艰难了得.最关键的是,目前还没有达到目的!!! 先记录下过程,有时间再来一遍,也许我已 ...
- Linux环境下Redis安装配置步骤[转]
在LInux下安装Redis的步骤如下: 1.首先下载一个Redis安装包,官网下载地址为:https://redis.io/ 2.在Linux下解压redis: tar -zxvf redis-2. ...
- php base64_encode,serialize对于存入数据表中字段的数据处理方案
A better way to save to Database $toDatabse = base64_encode(serialize($data)); // Save to database $ ...
- 【WP8】ScrollViewer滑动到底触发器(ListBox失效)
很多时候会有到底加载更多的需求,而ScrollViewer不支持继承,无法继承它进行扩展,只能通过触发器来控制到底的事件(当然,可以通过UserControl去扩展) 思路:定义一个Trigger,自 ...
- 在jsp中使用jstl,不使用JS,实现递归,生成N级菜单
参考材料: http://blog.csdn.net/kimsoft/article/details/7801564 我的实现: 1.我的recursionMenu.jsp代码如下: <%@ ...
- c++Valgrind内存检测工具---19
原创博文,转载请标明出处--周学伟 http://www.cnblogs.com/zxouxuewei/ 一.Valgrind 概述 Valgrind是一套Linux下,开放源代码(GPL V2)的 ...
- ios开发之--实现TextView提示文字并且输入字数限制
实现字数控制和限制,并展示当前输入的字符串长度,以及按钮的点击状态,代码如下: 1,设置代理 @interface FKViewController ()<UITextViewDelegate& ...
- pgpool-II 的使用
1.pgpool-II的概念 pgpool-II 是一个位于 PostgreSQL 服务器和 PostgreSQL 数据库客户端之间的中间件,它提供以下功能: 连接池 pgpool-II 保持已经连接 ...
- PostgreSQL存储过程(5)-异常错误处理
1. 异常错误处理 在PL/pgSQL函数中,如果没有异常捕获,函数会在发生错误时直接退出,与其相关的事物也会随之回滚.我们可以通过使用带有EXCEPTION子句的BEGIN块来捕获异常并使其从中恢复 ...
- INSTALL_FAILED_USER_RESTRICTED
我这里出问的问题是在 清单文件中 <provider <mate_data 中少了 android:resource="@xml/filepaths" 加上就好 了