0

I have a bit of code which used pthread_cond_wait which looks like this:

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

But I get a linker error on compilation,

undefined symbol clock_gettime ... first referenced in (the file with that code)

This is the only linker error I get; if I comment out this block of code it compiles, so the pthread library is loading. I read somewhere that I need the -lc flag set, which I have done but it appears that I need to set something else too.

Does anybody know what?

This is on Solaris 10, using Sun's 5.8 compiler.

4

2 回答 2

3

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

于 2009-07-08T11:12:52.680 回答
1

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

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

于 2009-07-08T11:14:28.950 回答