clock_gettime() problem

From: Charlie Liu (charlie@sensoray.com)
Date: Tue Apr 08 2003 - 17:30:03 EST


Hi All,

Can anybody tell me what's the problem with my simple program calling
clock_gettime() below.

I have tried to compile the app under SuSE 8.1 & RedHad 7.2, but always got
error message like:
In Function 'main': undefined reference to 'clock_gettime'

It's defined in </usr/include/time.h>. Did I miss someting alse? How to fix
it?

Thank you for any hit(s).

--Charlie

----------------------------------------------------------------------------
-------------------
# gcc -o main main.c

main.c:

/*
 * This program calculates the time required to
 * execute the program specified as its first argument.
 * The time is printed in seconds, on standard out.
 */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>

#define BILLION 1000000000L;

int main( int argc, char** argv )
  {
    struct timespec start, stop;
    double accum;

    if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) {
      perror( "clock gettime" );
      return EXIT_FAILURE;
    }

    system( argv[1] );

    if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) {
      perror( "clock gettime" );
      return EXIT_FAILURE;
    }

    accum = ( stop.tv_sec - start.tv_sec )
             + (double)( stop.tv_nsec - start.tv_nsec )
               / (double)BILLION;
    printf( "%lf\n", accum );
    return EXIT_SUCCESS;
  }

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html



This archive was generated by hypermail 2b29 : Tue Apr 15 2003 - 22:00:01 EST