libiconv-1.14 error: ‘gets’ undeclared here (not in a function)

本文介绍了解决在CentOS7环境中编译安装libiconv-1.14时遇到的一个关于stdio.h中未声明的gets函数错误的方法。通过修改srclib/stdio.h文件中的特定行来规避该问题,确保编译过程能够顺利完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centos7下编译安装libiconv-1.14报错,信息如下:

1
2
3
4
5
6
7
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");
  ^
make[1]: *** [progname.o] Error 1
make[1]: Leaving directory `/root/lnmp1.2/source/libiconv-1.14/srclib'
make: *** [all] Error 2

解决方法:
编辑 libiconv-1.14/srclib/stdio.h 文件,这个文件在make之后才会生成,源码中是没有的。

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

第1010行,把 _GL_WARN_ON_USE (gets, “gets is a security hole – use fgets instead”); 外面加一个if,
改为:

1
2
3
#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 通过

原创文章,转载请注明。本文链接地址: http://www.rootop.org/pages/3532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值