1dot0
Posts: 379
Joined: Mon Nov 28, 2016 12:31 pm

importance of flag -lrt ?

Fri Aug 11, 2017 10:19 am

hello,
sometimes I found the compiler flag -lrt in some examples, probably related to librt.so - but what is the importance?
Somewhere was written it is only important for cross-compiling, not for local compiling (still uncertain about the purpose), and somewhere I read (IIRC) that it is a real-time extension to pigpio, also without mentioning what is is doing exactly.
What is true now, and for which purposes does -lrt make sense?

User avatar
topguy
Posts: 3501
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: importance of flag -lrt ?

Fri Aug 11, 2017 2:24 pm

Probably cant give better explanation than the man page:
https://docs.oracle.com/cd/E19455-01/80 ... index.html

1dot0
Posts: 379
Joined: Mon Nov 28, 2016 12:31 pm

Re: importance of flag -lrt ?

Sat Aug 12, 2017 4:10 pm

topguy wrote:
Fri Aug 11, 2017 2:24 pm
Probably cant give better explanation than the man page:
https://docs.oracle.com/cd/E19455-01/80 ... index.html
thank you, so does that mean: if one does not use either of the following functions then one would never need to use -lrt, correct?

Code: Select all

 SUNW_1.1 (generic):
aio_cancel	aio_error	aio_fsync
aio_read	aio_return	aio_suspend
aio_write	clock_getres	clock_gettime
clock_settime	fdatasync	lio_listio
mq_close	mq_getattr	mq_notify
mq_open	mq_receive	mq_send
mq_setattr	mq_unlink	nanosleep
sched_getparam	sched_get_priority_	sched_get_priority_
  	max	min
sched_getscheduler	sched_rr_get_	sched_setparam
  	interval	 
sched_setscheduler	sched_yield	sem_close
sem_destroy	sem_getvalue	sem_init
sem_open	sem_post	sem_trywait
sem_unlink	sem_wait	shm_open
shm_unlink	sigqueue	sigtimedwait
sigwaitinfo	timer_create	timer_delete
timer_getoverrun	timer_gettime	timer_settime

User avatar
PeterO
Posts: 3613
Joined: Sun Jul 22, 2012 4:14 pm

Re: importance of flag -lrt ?

Sat Aug 12, 2017 4:33 pm

topguy wrote:
Fri Aug 11, 2017 2:24 pm
Probably cant give better explanation than the man page:
https://docs.oracle.com/cd/E19455-01/80 ... index.html
That man page is misleading....

On Raspbian it doesn't seem to exist. I took one of the functions mentioned and on Raspbian in has it's own man page ....

Code: Select all

SEM_OPEN(3)                                             Linux Programmer's Manual                                            SEM_OPEN(3)

NAME
       sem_open - initialize and open a named semaphore

SYNOPSIS
       #include <fcntl.h>           /* For O_* constants */
       #include <sys/stat.h>        /* For mode constants */
       #include <semaphore.h>

       sem_t *sem_open(const char *name, int oflag);
       sem_t *sem_open(const char *name, int oflag,
                       mode_t mode, unsigned int value);

       Link with -pthread.
Note the last line. It seems the Oracle manual page you linked to is not appropriate to Raspbian.....

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

LdB
Posts: 547
Joined: Wed Dec 07, 2016 2:29 pm

Re: importance of flag -lrt ?

Sat Aug 12, 2017 5:44 pm

All the answers are sort of correct :-)

librt has been deprecated in part or whole on a number of libraries and compilers most noticably new versions of Glibc. So there is no one answer here it depends what compiler and library versions you are using.

If you are using the Raspbian compiler GCC 4.8 or whatever as is there is probably a definitive answer which I am guessing is the one Peter O gave. If you updated your library or compiler you may have a different answer.

The easy answer is you need it when the linker complains that it can't find the functions that form part of the library .. try compiling without it :-)

1dot0
Posts: 379
Joined: Mon Nov 28, 2016 12:31 pm

Re: importance of flag -lrt ?

Sun Aug 13, 2017 8:26 am

LdB wrote:
Sat Aug 12, 2017 5:44 pm
All the answers are sort of correct :-)

librt has been deprecated in part or whole on a number of libraries and compilers most noticably new versions of Glibc. So there is no one answer here it depends what compiler and library versions you are using.

If you are using the Raspbian compiler GCC 4.8 or whatever as is there is probably a definitive answer which I am guessing is the one Peter O gave. If you updated your library or compiler you may have a different answer.

The easy answer is you need it when the linker complains that it can't find the functions that form part of the library .. try compiling without it :-)
@all,
thank you very much for your answers. Indeed where I found this -lrt were older sources using pthread and pigpio, sometimes also wiringPi IIRC.
But that it's probably now outdated and deprecated for the Pi is the most plausible reason that the ones I tried also compiled without -lrt, too.

jahboater
Posts: 1782
Joined: Wed Feb 04, 2015 6:38 pm

Re: importance of flag -lrt ?

Sun Aug 13, 2017 9:46 am

Yes, some things have been moved into the main glibc library.
For example

Code: Select all

 
       int clock_settime(clockid_t clk_id, const struct timespec *tp);

       Link with -lrt (only for glibc versions before 2.17).

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 2 guests