[mapserver-dev] PHP4 + Swig

Alex Rice alex_rice at arc.to
Thu Aug 15 16:42:06 EDT 2002


On Thursday, August 15, 2002, at 02:06  PM, Daniel Morissette wrote:
>> I had SWIG 1.3+PHP in my hit list for quite a while, but it 
>> keeps being
>> pushed back.  I wouldn't expect things to work right out of the 
>> box with
>> SWIG since PHP support is very new, but I would be interested in 
>> hearing
>> your mileage with SWIG+PHP... perhaps you could send your feedback on
>> this via the mapserver-dev list where I think this type of low-level
>> discussion belongs more.

Using Swig 1.3.13 and mapscript.i, I was able to get a PHP 
extension to compile on PHP 4.2.2 (meaning all the Swig-created 
functions compiled and php -m reported a "mapscript" extension) 
This is not a dynamically loadable .so extension, it's a built in 
extension-- since on OS X PHP doesn't have dynamic extensions for 
PHP. Still don't know why that is.

I did not even try calling and of the mapscript functions because 
I got stuck linking the ten or so libraries my libmap.a 
references... gd, ttf, png, etc. etc. That's going to be tricky. 
It involves making a sufficiently smart config.4 which the PHP 
configuration machinery will use get the appropriate -L and -l 
switches. There are macros for all that and there are lots of 
examples in PHP's ext/ directory. But currently I think once 
could build a PHP mapscript using Swig, if one didn't have a lit 
of junk linked in libmap.a.

Basically the process I was using is this, if anyone else wants 
to compare notes. And also so I don't forget myself how I did it.

o  Create an empty php4/ subfolder in your mapscript source.
# cd mapserver-src/mapscript
# mkdir php4

o  Copy mapscript.i into there, or symlink it into there.
# cd php4
# ln -s ../mapscript.i mapscript.i

o  Swig mapscript.i.
  # swig  -php -shadow mapscript.i
(warning requires Swig 1.3.x from www.swig.org, compiled with 
PHP4 support)
(note - I gave up on swig's -phpfull option because PHP 4.2.2 
seems to want different files)

o Now in PHP 4 source tree create a new extension skeleton.
# cd ext
# ./ext_skel --extname=mapscript

o Edit the ext/mapscript/config.m4.

	- Uncomment the line that says --with-mapscript.

	- Add macros for your include path (relative to the .h files 
which SWIG generated,  e.g. "../../map.h", and add other required 
libraries to the linking process.

	- Other extensions typically use this space for checking if 
supporing stuff is existing, and if library versions are OK. See 
for example ext/ming for a simple one that deals with one 
external library to link with.

o Copy swig-generated files over from your mapscript folder to 
php-src/ext/mapscript. Rename mapscript_wrap.c to mapscript.c.

o In PHP 4 source tree do, reconfigure and rebuilt. (buildconf 
requires libtool 1.4)

# ./buildconf
# ./configure --with-mapscript --etc...
# make

Alex Rice, Software Developer
Architectural Research Consultants, Inc.
alex_rice at arc.to
alrice at swcp.com





More information about the mapserver-dev mailing list