怎样编译安装libiconv

2017年1月9日 | 分类: 【技术】

【介绍】

官网:http://www.gnu.org/software/libiconv/

参考:http://www.linuxfromscratch.org/lfs/view/6.5/chapter06/glibc.html

Glibc provides an iconv() implementation and can convert from/to Unicode, therefore libiconv is not required on an LFS system.

在编译 PHP ,make 时报错:

/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
make: *** [libphp7.la] Error 1

尝试:

make ZEND_EXTRA_LIBS='-liconv'

【yum安装】

yum install glibc glibc-devel

phpinfo 中显示:

iconv
iconv support enabled
iconv implementation glibc
iconv library version 2.17

【从源码编译安装】

下载:http://ftp.gnu.org/pub/gnu/libiconv/

最新版本:libiconv-1.15.tar.gz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz && tar xvf libiconv-1.15.tar.gz && cd libiconv-1.15 && ./configure --prefix=/usr/local && make && make install

输出:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib
...
/bin/sh ./build-aux/mkinstalldirs /usr/local/include
/usr/bin/install -c -m 644 include/libcharset.h /usr/local/include/libcharset.h
...

如果make时报错:./stdio.h:456:1: error: ‘gets’ undeclared here (not in a function)

报错提示建议用:fgets。

参考资料:http://www.cnblogs.com/hjj801006/p/3988220
参考资料:http://www.cnblogs.com/awsqsh/articles/4337423

解决办法:

编辑 ./srclib/stdio.in.h 第695行:gets is a security hole 然后将该行注释掉重新编译。

/* It is very rare that the developer ever has full control of stdin,
   so any use of gets warrants an unconditional warning.  Assume it is
   always declared, since it is required by C89.  */
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

换成:

/* It is very rare that the developer ever has full control of stdin,
   so any use of gets warrants an unconditional warning.  Assume it is
   always declared, since it is required by C89.  */
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
#endif

重新make,顺利通过。