undefined reference to `libiconv' collect2: error

研究 PHP 源码的时候进行 make 之后报错:

/cli/ps_title.o sapi/cli/php_cli_process_title.o -lcrypt -lresolv -lcrypt -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt  -o sapi/cli/php
ext/iconv/iconv.o: In function `php_iconv_stream_filter_dtor':
/home/work/tmp/php-src/ext/iconv/iconv.c:2513: undefined reference to `libiconv_close'
ext/iconv/iconv.o: In function `php_iconv_stream_filter_ctor':
/home/work/tmp/php-src/ext/iconv/iconv.c:2534: undefined reference to `libiconv_open'
ext/iconv/iconv.o: In function `_php_iconv_strlen':
/home/work/tmp/php-src/ext/iconv/iconv.c:668: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:692: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:726: undefined reference to `libiconv_close'
ext/iconv/iconv.o: In function `_php_iconv_appendl':
/home/work/tmp/php-src/ext/iconv/iconv.c:391: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:425: undefined reference to `libiconv'
ext/iconv/iconv.o: In function `_php_iconv_substr':
/home/work/tmp/php-src/ext/iconv/iconv.c:789: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:813: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:868: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:872: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:821: undefined reference to `libiconv_open'
ext/iconv/iconv.o: In function `_php_iconv_mime_encode':
/home/work/tmp/php-src/ext/iconv/iconv.c:1107: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:1121: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:1293: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1325: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1381: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:1384: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:1240: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1192: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1224: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1368: undefined reference to `libiconv'
ext/iconv/iconv.o: In function `_php_iconv_mime_decode':
/home/work/tmp/php-src/ext/iconv/iconv.c:1419: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:1941: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:1944: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:1557: undefined reference to `libiconv_close'
/home/work/tmp/php-src/ext/iconv/iconv.c:1560: undefined reference to `libiconv_open'
ext/iconv/iconv.o: In function `php_iconv_stream_filter_append_bucket':
/home/work/tmp/php-src/ext/iconv/iconv.c:2578: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:2651: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:2650: undefined reference to `libiconv'
ext/iconv/iconv.o: In function `php_iconv_string':
/home/work/tmp/php-src/ext/iconv/iconv.c:497: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:506: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:522: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:532: undefined reference to `libiconv_close'
ext/iconv/iconv.o: In function `_php_iconv_strpos':
/home/work/tmp/php-src/ext/iconv/iconv.c:916: undefined reference to `libiconv_open'
/home/work/tmp/php-src/ext/iconv/iconv.c:944: undefined reference to `libiconv'
/home/work/tmp/php-src/ext/iconv/iconv.c:1058: undefined reference to `libiconv_close'
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

表面看,是libiconv安装问题,重装libiconv之后问题依旧,网上看有人舍弃libiconv,使用 –without-iconv,觉得不可取,这样是回避问题。 找了n久,终于找到bug所在: 在执行完 ./configure … 之后,修改下 Makefile,找到其中的

EXTRA_LIBS = -lcrypt -lresolv -lcrypt -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt

在其后增加一个 -liconv 参数:

EXTRA_LIBS = -lcrypt -lresolv -lcrypt -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt -liconv

参考:
PHP 编译安装时出现 undefined reference to `libiconv’ 错误的解决方法

    原文作者:老K8
    原文地址: https://blog.51cto.com/laok8/2451670
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞