编译安装libiconv报错./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)

温馨提示:文章已超过1880天没有更新,可能存在链接失效,相关教程仅供参考

In file included from progname.c:26:0:
./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 ^
Makefile:914: recipe for target 'progname.o' failed
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory '/usr/local/src/libiconv-1.14/srclib'
Makefile:865: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/local/src/libiconv-1.14/srclib'
Makefile:33: recipe for target 'all' failed
make: *** [all] Error 2

image.png

解决办法

1、编辑源码包目录下的stdio.in.h文件

# vi /usr/local/src/libiconv-1.14/srclib/stdio.in.h

通过关键字 gets 找到

/* 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");

image.png

修改添加如下代码,如下图

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

image.png

或者直接删除

/* 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");

替换成

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

然后重新make && make install,问题解决。

© 除非注明,否则均为阿豪运维笔记原创文章,转载或复制请以超链接形式并注明出处

取消
微信二维码
微信二维码
支付宝二维码