LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   clock_gettime() issue (http://www.linuxquestions.org/questions/programming-9/clock_gettime-issue-429432/)

AndreiCiprian 03-28-2006 07: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.
Code:

        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:
Code:

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
Code:

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 12:59 PM.