warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]

2.8k views Asked by At

I have a lib.h file, inside which I use the function gettimeofday:

struct timeval tn;
struct tm *time;
gettimeofday(&tn, NULL);
time = gmtime(&tn.tv_sec);

I included the library time.h:

#include <time.h>

And the function works perfectly, I can correctly print the time of the day. Then why is this warning happening?

In file included from main.c:1:
lib.h: In function ‘execute_remote_script’:
lib.h:86:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
   86 |     gettimeofday(&tn, NULL);

In main.c:

#include "lib.h"
1

There are 1 answers

1
Ahmet Korkmaz On

add #include <sys/time.h>