A compilation error occurred while using clock_gettime in c99

when I use clock_gettime in my code snippet and compile with the -std = c99 flag, I got this error:

warning: implicit declaration of function 'clock_gettime' error: 'CLOCK_REALTIME' undeclared (first use in this function) 

and I included the file "time.h". who knows how to fix it.

+8
c c99
source share
1 answer

in the source code with -std = c99, try adding

 #define _POSIX_C_SOURCE >= 199309L 

The man page for clock_gettime indicates that this is a necessary requirement of the function check macro.

+7
source share

All Articles