Mac 上编译 PHP 5.4/5.5/5.6 出错 Undefined symbols for architecture x86_64: "_libiconv", referenced from
问题描述
在 Mac 电脑中,编译 PHP 5系列(5.4.45/5.5.38/5.6.40)的源码。运行以下命令。
$ ./configure --prefix=/opt/php-5.4.45 --enable-fpm --with-mysql
$ make
在运行 make
的时候,报错了。
Undefined symbols for architecture x86_64:
"_libiconv", referenced from:
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_string in iconv.o
__php_iconv_strlen in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_appendl in iconv.o
_php_iconv_stream_filter_append_bucket in iconv.o
...
"_libiconv_close", referenced from:
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_string in iconv.o
__php_iconv_strlen in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_mime_decode in iconv.o
_php_iconv_stream_filter_factory_create in iconv.o
...
"_libiconv_open", referenced from:
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_string in iconv.o
__php_iconv_strlen in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_mime_decode in iconv.o
_php_iconv_stream_filter_factory_create in iconv.o
...
解决方法
Mac 自带了 libiconv
,但是并适合 PHP 5。
1. 重新安装 libiconv
运行 brew
重新安装 libiconv
。
brew install libiconv
查看 libiconv.dylib
的路径,我的电脑是在 /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib
。
2. 修改 Makefile
打开当前目录的 Makefile
文件,搜索 -liconv
,找到以下一行。
EXTRA_LIBS = -lresolv -liconv -liconv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm
删除 -liconv
,并在行最后,添加第一步的 libiconv.dylib
路径。修改结果如下。
- EXTRA_LIBS = -lresolv -liconv -liconv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm
+ EXTRA_LIBS = -lresolv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/opt/libiconv/lib/libiconv.dylib
3. 重新编译
$ make
$ sudo make install