2014-05-20 54 views
0

希望這是一個簡單的問題,並帶有一個簡單的答案。代碼用C編寫。 我使用MPLAB IDE v1.60和XC8編譯器,但它不識別「clock_t」。我將MPLAB設置爲器件PIC18F6520。 當我嘗試構建時出現的錯誤消息如下;clock_t沒有用MPLAB XC8編譯

ClockTimer.c:16: error: undefined identifier "clock_t" 
ClockTimer.c:16: error: expression syntax 
ClockTimer.c:18: error: expression syntax 
ClockTimer.c:19: error: undefined identifier "stop" 
ClockTimer.c:19: error: undefined identifier "start" 

代碼如下;

#include <stdio.h> 
#include <stdlib.h> 
#include <xc.h> 
#include <time.h> 


int main() 
{ 
    clock_t start = clock(); 
    // Execuatable code 
    clock_t stop = clock(); 
    double elapsed = (double)(stop - start) * 1000.0/CLOCKS_PER_SEC; 
    printf("Time elapsed in ms: %f", elapsed); 

} 

任何想法,爲什麼這不是編譯? 感謝 馬克

+0

閱讀編譯器文檔,可能庫不支持這些功能。 –

回答

0

由於用clock_t往往只是unsigned long類型的別名,嘗試在IDE無法找到文件

unsigned long start = clock();

0

有時我發現的問題進行編譯。嘗試從庫中複製文件並將其直接放在項目文件夾中,然後包含爲「time.h」,並且問題應該修復。

希望這會有所幫助!