Mac OSX上重新编译PHP后提示Syntax error的解决办法

Mac OS X 对于非开发人员提供了很好的体验,对于Web开发人员也很厚道。不但提供了Apache Web Server、FTP Server,还集成了很多开发环境:C、Python、PHP等等,而且版本比较新,扩展也很完善。可套餐终归是不如单点。在产品经理的各式各样需求前面,终于还是闹饥荒了。

不久之前由于需要PHP扩展的freetype模块,但是系统本身没有内建,所以只能自己动手。首先想到的是编译成动态扩展库的方式,按照装各种lib都很顺畅,也成功的编译gd.so文件。但是由于系统的PHP已经内建了gd,再load此文件会报错,google一番无解,所以只好放弃。重新编译吧,没有别的办法了。编译过程比较顺利,和Linux下过程一样,不在啰嗦了。但是重启Apache的时候出现下面的提示:

httpd: Syntax error on line 117 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): Symbol not found: __cg_png_create_info_struct
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/lib/libpng15.15.dylib
in /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIObogon:php-5.3.6


这下麻烦了,提示语法错误,貌似是没有找到“__cg_png_create_info_struct”。花费了很多时间google,最后终于找到了解决办法:

sudo ln -sf /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib /usr/lib/libpng.dylib

然后重新启动Apache,一切正常!

为什么这样就可以了呢?这是因为当OSX需要载入libPng.dylib的时候,系统总是去搜索/usr/lib/。我想这可能是因为在重新编译libpng之后,新的文件与mac系统不兼容所致。我们生成一个新的符号链接,强制OSX去使用系统的libpng.dyld就解决了这个问题。相似的问题也可以很容易的解决,比如下面的错误:

dyld: Symbol not found: _gll_noop
Referenced from:
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
Expected in: /opt/local/lib/libGL.dylib

dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from:
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libJPEG.dylib

dyld: lazy symbol binding failed: Symbol not found: __cg_TIFFSetErrorHandler
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libTIFF.dylib

dyld: Symbol not found: __cg_png_create_info_struct
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /optlocal/lib/libPng.dylib
Then congratulations, you’ve discovered that OSX and MacPorts are incompatible with each other for these libraries! For example, Macport’s libjpeg contains the symbol _jpeg_resync_to_restart, but not what Apple is looking for, __cg_jpeg_resync_to_restart.

解决办法,照猫画虎:

sudo ln -sf /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib /opt/local/lib/libGL.dylib
sudo ln -sf /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib /opt/local/lib/libtiff.dylib
sudo ln -sf /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib /opt/local/lib/libjpeg.dylib

参考:http://lists.macosforge.org/pipermail/macports-users/2010-November/022662.html

暂无评论

发表评论

电子邮件地址不会被公开。