implicit declaration of function ‘usleep’

user3785202 picture user3785202 · Mar 31, 2015 · Viewed 10.9k times · Source

So i've been looking stuff about usleep() and all I have found to get rid of this is #define which i have done... Any ohter suggestion? I need to get rid of this warning... Or any ideas on how to use sleep with miliseconds.

#define _BSB_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>

int r = rand() % 1000 +1;
usleep(r*1000);        
pthread_mutex_lock (&count_mutex);

Answer

Iharob Al Asimi picture Iharob Al Asimi · Mar 31, 2015

You need to remove -std=c99 from your compiler command or use the _XOPEN_SOURCE macro before including unistd.h.

If you want you can use -std=gnu99 instead of -std=c99.