警告:内置函数“xyz"的隐式声明不兼容 [英] warning: incompatible implicit declaration of built-in function ‘xyz’

查看:63
本文介绍了警告:内置函数“xyz"的隐式声明不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 中,使用以前未声明的函数构成函数的隐式声明.在隐式声明中,如果我没记错的话,返回类型是 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,您应该尝试:

#include <string.h>

那是定义 strcpystrncpy 的地方,至少根据 strcpy(2) 手册页.

That's where strcpy and strncpy are defined, at least according to the strcpy(2) man page.

exit 函数是在 stdlib.h 中定义的,所以我不知道那里发生了什么.

The exit function is defined in stdlib.h, though, so I don't know what's going on there.

这篇关于警告:内置函数“xyz"的隐式声明不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆