问题描述
我编译了一些二进制文件时,取得了一些这些警告:
I'm getting a number of these warnings when compiling a few binaries:
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’
要设法解决这个问题,我已经添加了
To try to resolve this, I have added
#include <stdlib.h>
在此警告相关的C文件的顶部,除了与以下标志编译:
at the top of the C files associated with this warning, in addition to compiling with the following flags:
CFLAGS = -fno-builtin-exit -fno-builtin-strcat -fno-builtin-strncat -fno-builtin-strcpy -fno-builtin-strlen -fno-builtin-calloc
我使用GCC 4.1.2:
I am using GCC 4.1.2:
$ gcc --version
gcc (GCC) 4.1.2 20080704
我应该怎么做来解决这些警告?
What should I do to resolve these warnings?
推荐答案
在C,使用previously未声明的函数构成了功能的隐式声明。在一个隐含的声明中,返回类型是 INT
如果我没有记错。现在,GCC还内置了一些标准函数的定义。如果一个隐含的声明不匹配内置的定义,你得到这样的警告。
In C, using a previously undeclared function constitutes an implicit declaration of the function. In an implicit declaration, the return type is int
if I recall correctly. Now, GCC has built-in definitions for some standard functions. If an implicit declaration does not match the built-in definition, you get this warning.
要解决这个问题,必须在使用前声明函数;通常您可以通过包括适当的头做到这一点。我不建议如果可能的话使用-fno-builtin- *标志。
To fix the problem, you have to declare the functions before using them; normally you do this by including the appropriate header. I recommend not to use the -fno-builtin-* flags if possible.
相反stdlib.h中,你应该尝试
Instead of stdlib.h, you should try
#include <string.h>
这就是的strcpy
和函数strncpy
定义,至少根据的strcpy(2)手册页。
That's where strcpy
and strncpy
are defined, at least according to the strcpy(2) man page.
的退出
函数是在stdlib.h中定义,虽然如此,我不知道发生了什么事情在那里。
The exit
function is defined in stdlib.h, though, so I don't know what's going on there.
这篇关于警告:内建函数“XYZ”不兼容的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!