clock_getres用途 - 新手Linux下C [英] Use of clock_getres - newbie Linux C

查看:973
本文介绍了clock_getres用途 - 新手Linux下C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定我的Linux系统中定时器的粒度。据该男子页clock_getres,我应该能够使用这个代码片段:

I'm trying to determine the granularity of the timers on my Linux box. According to the man pages for clock_getres, I should be able to use this snippet:

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

我试图建立像这样:
    GCC -o timertest timertest.c

I'm trying to build like so: gcc -o timertest timertest.c

这在Solaris上的伟大工程,但在Linux上我得到的错误:

This works great on Solaris but on Linux I get the error:


/tmp/ccuqfrCK.o: In function `main':
timertest.c:(.text+0x49): undefined reference to `clock_getres'
collect2: ld returned 1 exit status

我试图传递给-lc GCC,显然是clock_getres libc中的定义,但它并没有区别。我必须在这里失去了一些东西简单 - 任何想法

I've tried passing -lc to gcc, apparently clock_getres is defined in libc, but it makes no difference. I must be missing something simple here - any ideas?

谢谢,

拉​​斯

推荐答案

您需要用RT库链接( -lrt

You need to link with with RT library (-lrt)

这篇关于clock_getres用途 - 新手Linux下C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆