需要为timer_create,timer_settime和其他与计时器相关的函数链接哪些库

15 linux posix timer

在Linux上编译调用POSIX定时器函数的程序(例如:timer_create,timer_settime)会返回错误,例如:

In function `foo':
timer.c:(.text+0xbb): undefined reference to `timer_create'
timer.c:(.text+0x187): undefined reference to `timer_settime'
collect2: ld returned 1 exit status

我需要链接哪个库?

小智 25

-lrt选项编译它.它会被编译.


小智 7

你可以试试gcc -o mytemer mytimer.c -lrt 它对我有用,但不是按这个顺序 gcc -lrt mytimer.c -o mytimer


小智 3

这应该记录在手册页中。鉴于它不是 add -lrt