简体   繁体   中英

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

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"

add #include <sys/time.h>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM