2014-04-10 2 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

감사합니다. –