Originally, I wanted to cast a struct timeval to a timespec one.
At first, it did not seem difficult, as a solution is proposed there: Is there a standard way to convert a struct timeval into a struct timespec?
A macro, TIMEVAL_TO_TIMESPEC
is supposed to do the job.
As indicated in the docs (https://www.daemon-systems.org/man/TIMEVAL_TO_TIMESPEC.3.html) it only asks for sys/time.h
to be included.
But I still get the same answer when I try to compile:`warning: implicit declaration of function ‘TIMEVAL_TO_TIMESPEC’ [-Wimplicit-function-declaration]
I even tried to compile the example given in the docs:
#include<time.h>
#include <assert.h>
#include<sys/time.h>
static void example(struct timespec *spec, time_t minutes) {
struct timeval elapsed;
(void)gettimeofday(&elapsed, NULL);
_DIAGASSERT(spec != NULL);
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
/* Add the offset for timeout in minutes. */
spec->tv_sec = spec->tv_sec + minutes * 60;
}
int main(){
return 0;
}
When compiling I get:
test.c: In function ‘example’:
test.c:10:2: warning: implicit declaration of function ‘_DIAGASSERT’ [-Wimplicit-function-declaration]
_DIAGASSERT(spec != NULL);
^
test.c:11:2: warning: implicit declaration of function ‘TIMEVAL_TO_TIMESPEC’ [-Wimplicit-function-declaration]
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
^
/tmp/ccqWnL9I.o: In function `example':
test.c:(.text+0x43): undefined reference to `_DIAGASSERT'
test.c:(.text+0x5b): undefined reference to `TIMEVAL_TO_TIMESPEC'
collect2: error: ld returned 1 exit status
What did I do that was wrong ?