usleep java,函数usleep的隐式声明

gcc (GCC) 4.6.3

c89

I am trying to use usleep. However, I keep getting the following warning:

implicit declaration of function usleep

I have included the unistd.h header file.

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?

解决方案

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.

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 :-)

Assuming you're using a glibc 2.12 or better, it means you either have to:

declare _BSD_SOURCE; or

declare a complicated combination of three other things, which I won't bother to decode.

Probably the easiest fix is to simply compile with gc -D _BSD_SOURCE or put:

#define _BSD_SOURCE

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值