首页 > 解决方案 > 警告:函数“timerisset”的隐式声明

问题描述

从较旧的 CentOS 服务器移动到具有相同 GCC 版本的较新服务器会导致编译 C 代码时出现错误,而该错误不会在旧服务器上发生:

interp.c: In function `update_userec':
interp.c:1100: warning: implicit declaration of function `timerisset'
interp.c:1101: warning: implicit declaration of function `timercmp'
interp.c:1101: error: syntax error before '<' token

代码:

if ( !timerisset(&userec->min_time)
||    timercmp(time_used, &userec->min_time, <) )
{

该文件确实在文件顶部有:

#include <time.h>

gcc 版本:

Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-19.el6)

手册页确实提到:

glibc 的功能测试宏要求(参见 feature_test_macros(7)):

   All functions shown above:
       Since glibc 2.19:
           _DEFAULT_SOURCE
       Glibc 2.19 and earlier:
           _BSD_SOURCE

但是定义_DEFAULT_SOURCE_BSD_SOURCE高于该include线并不能解决任何问题。

标签: ccentos

解决方案


推荐阅读