I'm trying to build a program that takes 2 timestamps: the timestamp at the end of a first process, then the timestamp at the start of a second process. Then get the delta of the two.
But I cannot compile because the linker complains about clock_gettime
, giving an undefined symbol error.
gcc (GCC) 3.2.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
struct timespec start, stop;
double timeStampFull1;
double timeStampFull2;
FILE *fOut;
fOut = fopen("fileOut.txt", "a");
if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) {
perror( "clock gettime" );
exit( EXIT_FAILURE );
}
timeStampFull1 = (double)start.tv_sec + (double)(start.tv_nsec/1000000000.0);
delay(1);
if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) {
perror( "clock gettime" );
exit( EXIT_FAILURE );
}
timeStampFull2 = (double)stop.tv_sec + (double)(stop.tv_nsec/1000000000.0);
printf("tv1: %f \n", timeStampFull1);
printf("tv2: %f \n", timeStampFull2);
fprintf(fOut, "TimeStartOfTest\t\t\t%f\n", timeStampFull1);
fprintf(fOut, "TimeEndOfTest\t\t\t%f\n", timeStampFull2);
fclose(fOut);
return 0;
}
Here is the compiler (linker) error:
gcc -Wall -o time ./time.c
time.c:49:2: warning: no newline at end of file
Undefined first referenced
symbol in file
clock_gettime /var/tmp//ccuu5CKe.o
ld: fatal: Symbol referencing errors. No output written to time
collect2: ld returned 1 exit status