警告:内置函数“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
我应该怎么做才能解决这些警告?
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>
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
I am using GCC 4.1.2:
$ gcc --version
gcc (GCC) 4.1.2 20080704
What should I do to resolve these warnings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于某些程序,这些错误是正常的,不应修复。
我在编译程序 phrap 时收到这些错误消息(例如)。 该程序恰好包含修改或替换某些内置函数的代码,当我包含适当的头文件来修复警告时,GCC 相反会生成一堆错误。 因此修复警告会有效地破坏构建。
如果您将源代码作为应该正常编译的发行版的一部分来获取,则错误可能是正常的。 请查阅文档以确定。
In the case of some programs, these errors are normal and should not be fixed.
I get these error messages when compiling the program phrap (for example). This program happens to contain code that modifies or replaces some built in functions, and when I include the appropriate header files to fix the warnings, GCC instead generates a bunch of errors. So fixing the warnings effectively breaks the build.
If you got the source as part of a distribution that should compile normally, the errors might be normal. Consult the documentation to be sure.
在 C 中,使用先前未声明的函数构成该函数的隐式声明。 如果我没记错的话,在隐式声明中,返回类型是 int 。 现在,GCC 已经内置了一些标准函数的定义。 如果隐式声明与内置定义不匹配,您会收到此警告。
要解决这个问题,您必须在使用函数之前声明它们; 通常,您可以通过包含适当的标头来完成此操作。 如果可能的话,我建议不要使用
-fno-builtin-*
标志。您应该尝试而不是 stdlib.h:
这是定义
strcpy
和strncpy
的地方,至少根据strcpy
代码>(2) 手册页。不过,
exit
函数是在 stdlib.h 中定义的,所以我不知道那里发生了什么。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.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.Instead of stdlib.h, you should try:
That's where
strcpy
andstrncpy
are defined, at least according to thestrcpy
(2) man page.The
exit
function is defined in stdlib.h, though, so I don't know what's going on there.这里是一些产生上述错误的 C 代码:
在 Fedora 17 Linux 64 位上使用 gcc 进行编译:
要使警告消失,请将此声明添加到文件顶部:
Here is some C code that produces the above mentioned error:
Compiled like this on Fedora 17 Linux 64 bit with gcc:
To make the warning go away, add this declaration to the top of the file:
我在
mempcpy
函数上遇到了这些警告。 手册页说这个函数是一个 GNU 扩展,概要显示:当
#define
在#include
之前添加到我的源代码时,GNU 扩展的声明变得可见并发出警告消失。I met these warnings on
mempcpy
function. Man page says this function is a GNU extension and synopsis shows:When
#define
is added to my source before the#include
, declarations for the GNU extensions are made visible and warnings disappear.