我試圖測量使用clock_gettime()
功能的運行時間獲得足夠的「未申報」的錯誤。我包括time.h
,我加-lrt
的Makefile文件,並添加基於Eclipse CDT正確的道路。然而,當我嘗試編譯我不斷收到這兩種錯誤:嘗試使用clock_gettime(),但是從time.h中
experiments.c: In function ‘main’:
experiments.c:137:2: error: unknown type name ‘timespec’
timespec time1, time2;
^
experiments.c:139:2: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
^
experiments.c:139:16: error: ‘CLOCK_PROCESS_CPUTIME_ID’ undeclared
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
這種情況與任何類型的CLOCK_
我嘗試使用。我一直在閱讀大量的問題/答案和教程,但一直沒能找到有幫助的東西。
我包括標頭是:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
我在Ubuntu 13.10 32位和具有以下CFLAGS
編制上gcc
:-g -Wall -pedantic -std=c99
如果我添加了標誌-D_POSIX_C_SOURCE=199309L
我得到error: unknown type name ‘timespec’
並警告使用timespec
。
這是代碼的一部分,以防萬一它有助於:
timespec time1, time2;
int temp;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
.
.
.
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
/*code stuff*/
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
感謝
你包含哪些頭文件? – Grantly 2014-11-05 23:30:50
關於'_POSIX_C_SOURCE> = 199309L'的手冊頁中有一個註釋,你試圖編譯它的是什麼? – 2014-11-05 23:49:32
@ DavidC.Rankin上的gcc編譯具有以下標誌:-g -Wall -pedantic -std = C99 – Francisca 2014-11-05 23:57:44