Add a C header include path to compile PECL extensions

I needed to use ImageMagick with PHP on Mac OS X.

Using homebrew I added ImageMagick to my system as follow :

$ brew install imagemagick

And then, add the PHP extension with PECL :

sudo pecl install imagick

Bad luck…

 cc -I. -I/private/tmp/pear/temp/imagick -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootSqBVOk/imagick-3.0.1/include -I/private/tmp/pear/temp/pear-build-rootSqBVOk/imagick-3.0.1/main -I/private/tmp/pear/temp/imagick -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/imagick/imagick_class.c -fno-common -DPIC -o .libs/imagick_class.o

In file included from /private/tmp/pear/temp/imagick/imagick_class.c:21:
/private/tmp/pear/temp/imagick/php_imagick.h:49:12: fatal error: 'wand/MagickWand.h' file not found
# include <wand/MagickWand.h>

configure found ImageMagick header :

checking for MagickWand.h header file... found in /usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick/wand/MagickWand.h

but couldn’t compile the source as the ‘wand/MagickWand.h’ include failed.

To solve it, just tell the C compiler where to find this header with the C_INCLUDE_PATH environment variable :

sudo C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick pecl install imagick

and it worked!

You should add "" to php.ini

I restarted Apache and see what happened :

dyld: lazy symbol binding failed: Symbol not found: _MagickWandGenesis
  Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/
  Expected in: flat namespace

dyld: Symbol not found: _MagickWandGenesis
  Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/
  Expected in: flat namespace

Bad luck!

So I manually compiled extension, following steps here and it worked fine this time…

Basically, the transcript is :

$ cd /usr/local/src/
$ wget
$ tar -xzvf imagick-3.0.1.tgz 
$ cd imagick-3.0.1
$ phpize
$ CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
$ CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
$ CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
$ LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
$ echo $CFLAGS
$ ./configure --with-imagick=/usr/local//Cellar/imagemagick/6.8.0-10
$ make
$ sudo make install
$ sudo vim /etc/php.ini
$ sudo apachectl restart

Extension with PECL compilation :

$ file /usr/lib/php/extensions/no-debug-non-zts-20090626/
/usr/lib/php/extensions/no-debug-non-zts-20090626/ Mach-O 64-bit bundle x86_64

Extension with manual compilation and corrects flags :

$ file /usr/lib/php/extensions/no-debug-non-zts-20090626/
/usr/lib/php/extensions/no-debug-non-zts-20090626/ Mach-O universal binary with 2 architectures
/usr/lib/php/extensions/no-debug-non-zts-20090626/ (for architecture i386):	Mach-O bundle i386
/usr/lib/php/extensions/no-debug-non-zts-20090626/ (for architecture x86_64):	Mach-O 64-bit bundle x86_64