开发者

undefined reference to `timer_getoverrun' fixed by passing -lrt to gcc. But why?

开发者 https://www.devze.com 2023-03-09 22:04 出处:网络
I was experimenting with a few timer functions and ended up with the above linker error. Someone on the net suggested to pass -lrt to gcc and it worked! What is \'-lrt\' and how did it help to overcom

I was experimenting with a few timer functions and ended up with the above linker error. Someone on the net suggested to pass -lrt to gcc and it worked! What is '-lrt' and how did it help to overcome this error?

I looked into gcc --help but couldn't find these options and the man page of gcc ( which is too huge ) also dint give much insight into t开发者_开发知识库his.


It adds the rt library to the linker (see librt) which amongst other things defines timer_getoverrun.


It's not in the gcc man page, because it's not an option. It's a library ( -l stands for library, this is the way, libs are passed to the linker)

rt is a time library. timer_getoverrun is just defined there.


The timer_getoverrun() function is implemented in librt.so. From the timer_getoverrun(2) man page:

SYNOPSIS
   ...

   Link with -lrt.
0

精彩评论

暂无评论...
验证码 换一张
取 消