I find some libraries are linked to librt.so
, while others are not. I am wondering in what circumstances it is linked.
I have never used this library directly. Is there any demo showing the direct usage of it? Is there a header file related to it?
The functions are for Real Time Solaris (Real Time means guaranteed response in a time boundary), which has since been integrated into mainline Solaris and is part of libc. Librt is present only for historical, backward compatibility reasons and you do not need to reference it.
$ nm /usr/lib32/librt.a | grep ' T ' | grep -v ' __'
00000000 T aio_cancel
00000000 T aio_error
00000000 T aio_fsync
00000000 T aio_read
00000000 T aio_read64
00000000 T aio_return
00000130 T aio_suspend
00000000 T aio_write
00000000 T aio_write64
00000000 T timer_create
00000000 T timer_delete
00000000 T timer_getoverrun
00000000 T timer_gettime
00000000 T timer_settime
00000000 T shm_open
00000000 T shm_unlink
00000000 T mq_open
00000000 T mq_close
00000000 T mq_unlink
00000000 T mq_getattr
00000000 T mq_setattr
00000310 T mq_notify
00000000 T mq_send
00000000 T mq_receive
And indeed if we look e.g. at man shm_open
, we see
Link with -lrt.
so the list of functions provided seems to be correct.
There is also this page from Solaris https://docs.oracle.com/cd/E86824_01/html/E54772/librt-3lib.html which explains that the librt library reexports some symbols actually implemented in libc and is there for historical reasons as it was specified in some versions of the Posix standard.