【问题标题】:pthread_cond_timedwait linking error with clock_gettime on Solaris 10pthread_cond_timedwait 在 Solaris 10 上与 clock_gettime 链接错误
【发布时间】:2009-07-08 10:20:12
【问题描述】:

我有一段代码使用了pthread_cond_wait,看起来像这样:

struct timespec ts;
clock_getttime(CLOCK_REALTIME, &timS);
ts.tv_sec += delay;

pthread_mutex_lock(&a_mutex);
     pthread_cond_timedwait(&thread_cond, &a_mutex,&timS);
pthread_mutex_unlock(&a_mutex);

但我在编译时遇到链接器错误,

未定义符号clock_gettime ...首先在(带有该代码的文件)中引用

这是我得到的唯一链接器错误;如果我注释掉它编译的这段代码,那么 pthread 库正在加载。我在某处读到我需要设置 -lc 标志,我已经这样做了,但似乎我还需要设置其他东西。

有人知道吗?

这是在 Solaris 10 上,使用 Sun 的 5.8 编译器。

【问题讨论】:

    标签: c++ time solaris pthreads


    【解决方案1】:

    -lc 的答案是错误的。您需要添加 -lrt (大概是实时的..?)

    【讨论】:

      【解决方案2】:

      在命令行上尝试“man clock_getttime”或“man -k clock_getttime”。这将为您提供要链接的库。 然后,将此行包含在您的 g++ -L/path/to/lib -lNameOfLib 中(或在生成文件中作为链接标志)

      Solaris Unix API 有时与标准 Unix 函数不同。

      【讨论】:

      • 谢谢,但我自己想通了,通过在 Google 中输入“clock_gettime solaris”。我第一次错过了,因为我太具体了。 Sun 的手册页概要下提到了“-lrt”位。它没有说“需要 rt 库”等。但现在我知道了 :-)
      • 实际上,POSIX 1003.1b 要求 clock_gettime 提供 -lrt,因此无论您使用哪种 UNIX,这都应该是相同的,除非它不兼容。
      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多