How to compile a PECL extension on Windows

Category PHP

Yesterday I had to enable the AMFExt on my desktop machine, which is running a Windows 7. This extension gives you ability to communicate with Flash/Flex applications in native way, very helpful.
Several PECL extensions has a Windows .dll ready to go, which is the case of the amfext, so I downloaded the version 0.9.0 and enabled on my machine.
Everything worked fine until I have some troubles, troubles regarding the version of the extension. I was using 0.9.0 but the server (both production and staging) were using the 0.9.2-dev version.

The command-line PELC (pecl install amfext) was not working, because it was unable to find a compiler. So the solution is nothing else to accomplish the impossible: Compile a PECL extension on Windows. At least it was what some guys told me, but it was not too difficult.

Once you had an version of the Microfost Visual C++ installed (I installed Visual C++ 2008 Express Edition) you are ready to go.
Just need to download an PHP source code package and the AMFExt source code package. Note that will don’t need to compile PHP, but AMFExt will use their files/headers to compile it.

Unpack the PHP to any folder you like, lets use C:\php-build here. When you unpacked you will have following structure:

C:\php-build\ext
C:\php-build\main
C:\php-build\netwear
... etc ...

Unpack the AMFExt to the C:\php-build\ext and rename the amfext-0.9.2 folder to amfext. Then open the C:\php-build\ext\amfext\amfext.dsp file using the VC++, this is an VC++ project file and will have all the necessary things to build the extension.
On the top part of the program choose the Release, instead of Debug, and build it. You will probably have an error like:
incompatible types - from 'time_t *' to '__time32_t *'

If you had it, add “/D _USE_32BIT_TIME_T=1″ to the “Additional options” on Properties > Configuration Properties > C/C++ > Command Line. Try to build it again and you will probably have the following error:
1>LINK : fatal error LNK1181: cannot open input file 'php5ts.lib'

If you had it, go to Properties > Configuration Properties > Linker > General and fill the field “Additional Library Directories” as the directory that have a php5ts.lib file. Save it and try to build again.
And voilà! If you get a message like:
Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped

You successfully compiled the AMFExt! Go to C:\php-build\ext, you will have a php_amf.dll file right there.

Comments2 Comments

2 Responses

  1. thank you for make simple a total pain

  2. Thanks. What do we do to compile the extension for the non-thread-safe version of PHP?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>