对“timer_getoverrun”的未定义引用通过-lrt对gcc进行修正。但是为什么呢?

时间:2022-05-08 19:33:51

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?

我尝试了一些定时器函数,最后得到了上面的链接器错误。网络上有人建议把-lrt传给gcc,它成功了!什么是-lrt,它如何帮助克服这个错误?

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 this.

我查看了gcc——帮助但是没有找到这些选项,而且gcc的手册页(太大了)也没有提供更多的信息。

3 个解决方案

#1


1  

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

它将rt库添加到链接器(参见librt),其中定义了timer_getoverrun。

#2


1  

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)

它不在gcc手册页中,因为它不是选项。它是一个库(-l代表library,这是方法,libs被传递给链接器)

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

rt是一个时间库。timer_getoverrun就是在这里定义的。

#3


1  

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

timer_getoverrun()函数在librt.so中实现。来自timer_getoverrun(2)手册页:

SYNOPSIS
   ...

   Link with -lrt.

#1


1  

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

它将rt库添加到链接器(参见librt),其中定义了timer_getoverrun。

#2


1  

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)

它不在gcc手册页中,因为它不是选项。它是一个库(-l代表library,这是方法,libs被传递给链接器)

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

rt是一个时间库。timer_getoverrun就是在这里定义的。

#3


1  

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

timer_getoverrun()函数在librt.so中实现。来自timer_getoverrun(2)手册页:

SYNOPSIS
   ...

   Link with -lrt.