2014-04-10 90 views
0

我正在使用下面的程序(這是一個網站上的演示)來查看執行過程中的時間。程序執行的時間計算?

#include <stdio.h> 
#include <unistd.h> 
#include <stdlib.h> 
#include <time.h> 
#define BILLION 1000000000 
int main(int argc, char **argv) 

{ 
    struct timespec start, stop; 
    double accum; 
    int val=clock_gettime(CLOCK_REALTIME,&start); 
    if(val==-1) { 
     perror("clock gettime"); 
     exit(EXIT_FAILURE); 
    } 

system(argv[1]); 
if(clock_gettime(CLOCK_REALTIME,&stop);) { 
    perror("clock gettime"); 
    exit(EXIT_FAILURE); 
    } 

printf("%lf\n", accum); 

return(EXIT_SUCCESS); 
} 

當我執行此代碼我收到以下錯誤

time.c :(文字+ 0x1d):未定義的引用clock_gettime' time.c:(.text+0x5f): undefined reference to clock_gettime」

你能告訴我爲什麼這和什麼將解決它?

回答

3

您需要鏈接到實時庫。嘗試gcc ... -lrt

+1

謝謝,它的工作 –