-   Programming (
-   -   clock_gettime() issue (

AndreiCiprian 03-28-2006 06:04 PM

clock_gettime() issue
My current homework is to compare execution times of the Boyer-Moore, Knuth-Morris-Pratt and Rabin-Karp algorithms.
Since the search is pretty fast I thought of using clock_gettime() so nanoseconds will be returned.

        struct timespec *ts;       
        t = clock_gettime(CLOCK_REALTIME, ts);
        printf("clock_gettime returns:\n");
        printf("%d seconds and %ld nanoseconds\n", ts->tv_sec, ts->tv_nsec);

When I compile I get the message:

system_time.c:(.text+0x43): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status

I have included <time.h>, and checked for the existence of clock_gettime() there.

Sorry for double posting, I tried

gcc -lrt -o time time.c
and it worked.

It seems that some types needed for the call are located in librt

All times are GMT -5. The time now is 06:27 PM.