私はLinuxのボックスでタイマーの細かさを判断しようとしています。clock_getres - newbieの使用Linux C
#include <time.h>
#include <stdio.h>
int main(int argc, char** argv)
{
clockid_t types[] = { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID, (clockid_t) - 1 };
struct timespec spec;
int i = 0;
for (i; types[i] != (clockid_t) - 1; i++)
{
if (clock_getres(types[i], &spec) != 0)
{
printf("Timer %d not supported.\n", types[i]);
}
else
{
printf("Timer: %d, Seconds: %ld Nanos: %ld\n", i, spec.tv_sec, spec.tv_nsec);
}
}
}
私はそうのように構築しようとしている:clock_getresのmanページによると、私はこのスニペットを使用することができるはずです のgcc -o timertest timertest.c
これは、Solaris上で素晴らしい作品しかし、Linux上で、私はエラーを取得:
/tmp/ccuqfrCK.o: In function `main': timertest.c:(.text+0x49): undefined reference to `clock_getres' collect2: ld returned 1 exit status
私はどうやらclock_getres、GCCに-lcを渡して試してみたがlibcの中で定義されているが、それは違いはありません。私はここで何か簡単なものを見逃しているに違いない - どんな考え?
おかげで、
ラス
Linuxの場合でも、clock_getresのマンページでは、「Link with -lrt」と表示されます。 Russ、あなたはLinuxがそのまま許してくれるのは幸いです。 – ephemient