怎样编译安装libiconv

2017年1月9日 由 Amon

【介绍】

官网:http://www.gnu.org/software/libiconv/
镜像:http://mirror.bjtu.edu.cn/gnu/libiconv/

【编译】

参考:http://www.linuxfromscratch.org/lfs/view/6.5/chapter06/glibc
下载:http://ftp.gnu.org/pub/gnu/libiconv/

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

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,顺利通过;继续 make install,输出:

...
Libraries have been installed in:
   /usr/local/lib
...

如果没安装,会在编译时报错:

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

更新系统动态连接库配置:

ldconfig

流程2:编译安装 libiconv-1.15

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

增加到动态链接库:

echo '/usr/local/libiconv/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
广告位
Sedo.com

评论已关闭.