簡體   English   中英

clock_t 未使用 MPLAB XC8 編譯

[英]clock_t not compiling with MPLAB XC8

希望這是一個簡單的問題,有一個簡單的答案。 代碼是用 C 編寫的。我使用的是帶有 XC8 編譯器的 MPLAB IDE v1.60,但它無法識別“clock_t”。 我為設備 PIC18F6520 設置了 MPLAB。 我嘗試構建時收到的錯誤消息如下;

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);

}

為什么這不能編譯的任何想法? 謝謝馬克

由於 clock_t 通常只是 unsigned long 的別名,請嘗試編譯

unsigned long start = clock();

有時我發現 IDE 找不到文件的問題。 嘗試從庫中復制文件並將其直接放入您的項目文件夾中,然后將其包含為“time.h”,您的問題應該得到解決。

希望這可以幫助!

XC8 用戶指南中的外觀表明time()clock()函數不是由 xc8 編譯器提供的,必須由用戶提供。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM