函数usleep的隐式声明 [英] implicit declaration of function usleep
问题描述
gcc (GCC) 4.6.3
c89
我想使用 usleep
。不过,我不断收到以下警告:
I am trying to use usleep
. However, I keep getting the following warning:
函数usleep的隐式声明
implicit declaration of function usleep
我已经包括 unistd.h中
头文件。
该名男子页提到一些有关这一点。但我不知道我将其理解:
The man pages mentions something about this. But I am not sure I understand by it:
usleep():
Since glibc 2.12:
_BSD_SOURCE ||
(_XOPEN_SOURCE >= 500 ||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
!(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
Before glibc 2.12:
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
但不知道我一个与上述呢?
But not sure what I a to do with the above?
推荐答案
这列表是具有 usleep
定义的pre-条件。这基本上是一个C-像前pression涉及的#define
变量,其中有包含头文件之前,是真实的。
That list is the pre-conditions for having usleep
defined. It's basically a C-like expression involving #define
variables which has to be true before including the header file.
头文件本身将只定义 usleep
里面是什么通常 #IFDEF
报表和一个巨大的鸟巢开发商花时间来告诉你,你需要做的,这样你就不必花费时间试图自己看着办吧: - )
The header file itself will only define usleep
inside what is usually a massive nest of #ifdef
statements and the developers have taken the time to tell you what you need to do so that you don't have to spend hours trying to figure it out yourself :-)
你使用假设的glibc
2.12或更高,这意味着你要么必须:
Assuming you're using a glibc
2.12 or better, it means you either have to:
- 申报_BSD_SOURCE;或
- 申报的其他三件事情,我也就懒得脱code一个复杂的组合。
也许最简单的解决方法是简单地用 GC -D _BSD_SOURCE编译
或放:
Probably the easiest fix is to simply compile with gc -D _BSD_SOURCE
or put:
#define _BSD_SOURCE
在code你包含头文件,让你在 usleep
。
in the code before you include the header file that gives you usleep
.
您可能会想之前定义这些的任何的包括的情况下有不同的头文件之间的依赖关系。
You'll probably want to define these before any includes in case there are dependencies between the various header files.
这篇关于函数usleep的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!