[Xapian-discuss] PHP Bindings with Cygwin : start of an HOWTO &
thomas at deniau.org
Thu Feb 16 09:18:09 GMT 2006
I have been trying for two days to get the PHP bindings compiled using Cygwin.
My goal here is to be able to compile the PHP bindings without Visual Studio,
and to try to have them recognized by a Windows binary distribution of PHP (a
Cygwin-built PHP would incur a major performance hit, and you would have to use
a Cygwin version of Apache...).
So, what we are trying to do is to use the Cygwin toolchain to produce a
"php_cygwin.dll" which would then be loaded by a native version of PHP.
* First step : the headers.
To compile the PHP bindings, you need the PHP headers. As these are produced
during the compilation of PHP, you have to generate them from a Cygwin
compilation process (./configure && make install-headers). You also need a
working php-config utility (make install-programs). The php-config that is
installed will then have an exec_dir for php set to /usr/local/bin &c. So you
have to change the paths to have it point to your real PHP install. Make sure
you get the exact same version for the source distribution and the binary
To be able to configure PHP, you need bison and flex from the Cygwin repository.
* Second step : the compilation.
This is now really easier thanks to Olly's changes in that last revisions (they
are in 0.9.3) as the flags needed to build a DLL are now passed to ld. 0.9.3 is
also much easier to compile than 0.9.2 because the SWIG-generated bindings used
to make gcc run out of memory when optimizing, and Olly fixed this.
To make that work, however, you have to install the 'file' package from the
Cygwin repository (Libtool doesn't detect its absence, but that's a Libtool
bug). To comply with UNIX conventions, you will also have to copy your
php5ts.dll file to "libphp5ts.dll"
As a Cygwin module for a Windows PHP isn't really a PHP target, php-config does
not report the paths, LDFLAGS, &c. needed for the compilation. So you will have
to use a "make xapian_la_LDFLAGS="-L/cygdrive/....youphpdir.... -lphp5ts". I
think you would use php4ts for php4 but I have not tried this.
* Where I'm stuck : ZTS
ZTS (Zend Thread Safety) is an experimental option during PHP's compilation.
Thread safety inside PHP is needed when you use it with an Apache 2 in threaded
ZTS is, by default, turned off in an Unix build and turned on in a Windows
build. So all the Windows binaries distributed by the PHP team (and several
other PHP distros) have ZTS enabled ; if you don't have Visual Studio and can't
build your own PHP, you're forced to have ZTS on.
If you didn't specify any specific flag when configuring PHP, as Cygwin is an
UNIX target, you will have ZTS off. ZTS being on meddles with some PHP global
variables (compiler_globals in our case) : they are no longer defined, so, if
you have PHP headers with ZTS on, you get an undefined symbol error.
Simple : you just have to use the --enable-maintainer-zts option when
configuring PHP, and you will get UNIX headers which match with your Windows
binary. And that's where I'm stuck : the PHP bindings are generated by SWIG and
SWIG isn't compatible with ZTS PHP yet (ZTS adds an argument to many functions ;
that's presumably needed for thread safety, and SWIG generates code without that
last argument). This SWIG bug is reportedly fixed in 1.3.27, but that last
argument isn't there when you generate the PHP bindings in 1.3.28. Makes me
wonder if the bug is really fixed.
Any idea ?
More information about the Xapian-discuss