I am facing some problems in my raspberry Pi 3 B+ when I compile this simple program that uses time library:
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
printf("Nsecs %d \n", now.tv_nsec);
return 0;
}
The output of the compilation shows these errors/warnings:
main.c: In function ‘main’: main.c: error: storage size of ‘now’ isn’t known struct timespec now;
main.c: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration] clock_gettime(CLOCK_REALTIME, &now);
main.c: error: ‘CLOCK_REALTIME’ undeclared (first use in this function) clock_gettime(CLOCK_REALTIME, &now);
I verified that the struct timespec
, the method clock_gettime
and the constant CLOCK_REALTIME
are available in time.h file.
I am compiling with gcc & C99. I am using NetBeans in a laptop to create the code and then I build on the raspberry (no problems so far in other projects). The command is:
gcc -c -g -std=c99 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.c
What is happening? Could you help me to understand it?