猿问

警告:内置函数“ xyz”的隐式声明不兼容

警告:内置函数“ xyz”的隐式声明不兼容

编译一些二进制文件时,我收到许多这样的警告:


warning: incompatible implicit declaration of built-in function ‘strcpy’

warning: incompatible implicit declaration of built-in function ‘strlen’

warning: incompatible implicit declaration of built-in function ‘exit’

为了解决这个问题,我添加了


#include <stdlib.h>

除了使用以下标志进行编译以外,还位于与此警告相关的C文件的顶部:


CFLAGS = -fno-builtin-exit -fno-builtin-strcat -fno-builtin-strncat -fno-builtin-strcpy -fno-builtin-strlen -fno-builtin-calloc

我正在使用GCC 4.1.2:


$ gcc --version

gcc (GCC) 4.1.2 20080704

我应该怎么做才能解决这些警告?


12345678_0001
浏览 705回答 4
4回答

不负相思意

对于某些程序,这些错误是正常现象,不应修复。我在编译程序phrap时收到这些错误消息(例如)。该程序恰好包含修改或替换某些内置函数的代码,当我包含适当的头文件来修复警告时,GCC会生成一堆错误。因此,修复警告会有效地破坏构建。如果您将源代码作为应该正常编译的发行版的一部分,则错误可能是正常的。请确保查阅文档

蓝山帝景

这是一些产生上述错误的C代码:int main(int argc, char **argv) {&nbsp; exit(1);}在带有gcc的Fedora 17 Linux 64位上像这样编译:el@defiant ~/foo2 $ gcc -o n n2.c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n2.c: In function ‘main’:n2.c:2:3: warning: incompatible implicit declaration of built-in&nbsp;function ‘exit’ [enabled by default]el@defiant ~/foo2 $ ./n&nbsp;el@defiant ~/foo2 $&nbsp;为了消除警告,请将以下声明添加到文件顶部:#include <stdlib.h>

慕哥6287543

我在mempcpy功能上遇到了这些警告。手册页中说此功能是GNU扩展,摘要显示:#define _GNU_SOURCE#include <string.h>在#define之前将#include_ 添加到我的源代码中,使GNU扩展的声明可见并且警告消失。
随时随地看视频慕课网APP
我要回答