I am trying to determine the granularity of the timers in my Linux box. According to the man pages for clock_getres, I have to use this snippet:
#include <time.h> #include <stdio.h> int main( int argc, char** argv ) { clockid_t types[] = { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID, (clockid_t) - 1 }; struct timespec spec; int i = 0; for ( i; types[i] != (clockid_t) - 1; i++ ) { if ( clock_getres( types[i], &spec ) != 0 ) { printf( "Timer %d not supported.\n", types[i] ); } else { printf( "Timer: %d, Seconds: %ld Nanos: %ld\n", i, spec.tv_sec, spec.tv_nsec ); } } }
I am trying to build like this: gcc -o timertest timertest.c
This works fine on Solaris, but on Linux I get the error:
/tmp/ccuqfrCK.o: In function `main ':
timertest.c :(. text + 0x49): undefined reference to `clock_getres'
collect2: ld returned 1 exit status
I tried passing -lc to gcc, obviously clock_getres is defined in libc, but that doesn't make any difference. I need to skip something simple - any ideas?
Thanks,
Russ
c linux
Russ Weeks
source share