readline AWOL?

Roger Oberholtzer roger at opq.se
Tue Nov 18 23:16:36 PST 2008


On Tue, 2008-11-18 at 16:04 +0000, Jorge Almeida wrote:
> On Tue, 18 Nov 2008, Roger Oberholtzer wrote:
> 
> > On Mon, 2008-11-17 at 20:40 +0000, Jorge Almeida wrote:
> >>  	$ gcc readtest.c
> >>  	/tmp/cc88uLvp.o: In function `main':
> >>  	readtest.c:(.text+0x19): undefined reference to `readline'
> >>  	collect2: ld returned 1 exit status
> >>  	$ ls /usr/include/readline
> >>  	chardefs.h  history.h  keymaps.h  readline.h  rlconf.h  rlstdc.h  rltypedefs.h  tilde.h
> >
> > It is not complaining about the C definition in the various include
> > files. It is complaining that it cannot find readline() when linking.
> > Try this compile command:
> >
> > 	gcc readtest.c -lreadline -lhistory
> >
> Ah, so that's it. I thought the -l options were needed only for stuff in
> nonstandard locations.
> There are still problems that were not expected with such a simple
> program:
>  	$ gcc readtest.c -lreadline -lhistory
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tgetnum'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tgoto'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tgetflag'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `BC'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tputs'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `PC'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tgetent'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `UP'
>  	/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libreadline.so: undefined reference to `tgetstr'
>  	collect2: ld returned 1 exit status
> 
> This happens in FC5 but not in Gentoo. I suppose the former (which I
> don't control) may have some problem. Back to learning readline, now.

When making a library, it is possible to tell the library what other
libraries it may need. Then the user need not specify them when
compiling a program with that library. This is why, quite often, ldd
lists libraries you did not specify and were not added by the compiler.
This third method brought them in. On Gentoo, you might run
'ldd ./your_program' to see what libs it is using. Look if they also
exist on Fedora. If so, try adding those as well.

or,

gcc has a one-pass linker. So, libs must be supplied in the right order.
It could also be the order of the -l options. Try turning them around.
This is the least likely.

-- 
Roger Oberholtzer

OPQ Systems / Ramböll RST

Ramböll Sverige AB
Krukmakargatan 21
P.O. Box 17009
SE-104 62 Stockholm, Sweden

Office: Int +46 8-615 60 20
Mobile: Int +46 70-815 1696

--

"On two occasions I have been asked (by members of Parliament!),
'Pray, Mr. Babbage, if you put into the machine wrong figures,
will the right answers come out?' I am not able rightly to apprehend
the kind of confusion of ideas that could provoke such a question.
  - Charles Babbage 1791-1871)
    English computer pioneer, philosopher

And remember:

It is RSofT and there is always something under construction. 
It is like talking about large city with all constructions finished. 
Not impossible, but very unlikely.




More information about the Linux-users mailing list