implicit declaration of function usleep

前端 未结 6 1901
庸人自扰
庸人自扰 2020-12-14 07:21
gcc (GCC) 4.6.3
c89

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

implicit declarat

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 07:27

    ANSWER TO QUESTION: use #define _BSD_SOURCE or #define _GNU_SOURCE

    For those with the error

    warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
     # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
       ^~~~~~~
    

    after using #define _BSD_SOURCE try using

    #define _GNU_SOURCE
    

    NOTE: use before you include the header that gives you usleep() i.e. before including unistd.h

提交回复
热议问题