简体   繁体   English

警告:函数“kill”的隐式声明

[英]warning: implicit declaration of function 'kill'

I am making these inclusions:我正在制作这些夹杂物:

#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

But still getting this warning.但仍然收到此警告。

You are probably passing the "-ansi -Wall" switches to the gcc compiler.您可能正在将“-ansi -Wall”开关传递给 gcc 编译器。 You can remove "-ansi" if you don't need it, otherwise try to set the proper feature define macro.如果不需要“-ansi”,可以删除它,否则请尝试设置适当的功能定义宏。

Something like:就像是:

#define _POSIX_SOURCE
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>

You can also define it on the compile time by adding this flag with gcc.您还可以在编译时通过使用 gcc 添加此标志来定义它。

-D_POSIX_C_SOURCE

ex:前任:

-g -D_POSIX_C_SOURCE -Wall -std=c99

According to the kill(2) Linux manual page, _POSIX_C_SOURCE must be #define d before any includes in order for the prototype of the function kill() to be included through <signal.h> if you are using glibc.根据kill(2) Linux 手册页, _POSIX_C_SOURCE在任何包含之前必须是#define d,以便在使用glibc 时通过<signal.h>包含函数kill() 的原型。

Your code will probably compile either way, since the binary is available for linking regardless of the defines, but that's the proper way to silence this warning according to the documentation.您的代码可能会以任何一种方式编译,因为无论定义如何,二进制文件都可用于链接,但这是根据文档消除此警告的正确方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM