undefined reference to `libiconv_open 無法編譯PHP libiconv

小亮520cl發表於2015-09-02
原文:http://hi.baidu.com/ostech/blog/item/a63f9b0dabed1ae7ab6457d0.html

./configure --with-mysql=/backup/mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-curl --with-gd --enable-gd-native-ttf --with-apxs2=/usr/local/apache/bin/apxs --enable-sockets --with-iconv
make時提示:
.....................................................
ext/iconv/.libs/iconv.o(.text+0x1738): In function `zif_iconv_mime_encode':
/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1017: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1756):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1031: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1993):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1290: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x19ad):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1293: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x1b01):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1102: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b33):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1134: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b5e):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1150: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e10):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1202: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e3c):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1233: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x207f):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:1277: more undefined references to `libiconv' follow
ext/iconv/.libs/iconv.o(.text+0x2c08): In function `php_iconv_stream_filter_dtor':
/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:2393: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x2cf2): In function `php_iconv_stream_filter_append_bucket':
/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x2d34):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x2de7):/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:2465: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x30e2): In function `php_iconv_stream_filter_factory_create':
/home/jjdai/work/zhupiter/php-5.2.0/ext/iconv/iconv.c:2419: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

解決方法:
#wget /> #tar -zxvf libiconv-1.13.1.tar.gz
#cd libiconv-1.13.1
# ./configure --prefix=/usr/local/libiconv
# make
# make install

再檢查php,指定 iconv的位置  --with-iconv=/usr/local/libiconv
#./configure --with-mysql=/backup/mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-curl --with-gd --enable-gd-native-ttf --with-apxs2=/usr/local/apache/bin/apxs --enable-sockets --with-iconv=/usr/local/libiconv
#make
#make install

另一種解決方法為去除iconv模組也能正常編譯php,如下:
編輯 Makefile 大約 77 行左右的地方:
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv
再執行make就可以了。

  1. 本人實驗方法二後,重啟httpd服務會報以下的錯誤,推薦使用第三種方法,可以解決

  2. httpd: Syntax error on line 57 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: libiconv_open


最後一種方法:由tonyty163提供:

#make ZEND_EXTRA_LIBS='-liconv'
#make install

版權宣告:本文為博主原創文章,未經博主允許不得轉載。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-1789541/,如需轉載,請註明出處,否則將追究法律責任。

相關文章