Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to "tputs" on compiling Readline

I want compile install readline library on Ubuntu.

I do the following:

wget http://git.savannah.gnu.org/cgit/readline.git/snapshot/readline-8.0.tar.gz
tar -zxvf readline-8.0.tar.gz
cd readline-8.0
./configure --prefix=`pwd`/readline
make
make install

It's right but when I use -lreadline option, I get error like this:

readline/lib/libreadline.so: undefined reference to `tputs'
readline/lib/libreadline.so: undefined reference to `tgoto'
readline/lib/libreadline.so: undefined reference to `tgetflag'
readline/lib/libreadline.so: undefined reference to `UP'
readline/lib/libreadline.so: undefined reference to `tgetent'
readline/lib/libreadline.so: undefined reference to `tgetnum'
readline/lib/libreadline.so: undefined reference to `PC'
readline/lib/libreadline.so: undefined reference to `tgetstr'

I want to know what wrong I did and why and what to do?

I'll appreciate it if you help me.

like image 285
Yunbin Liu Avatar asked Mar 05 '23 15:03

Yunbin Liu


1 Answers

Obviously you are missing to link against a library that readline relies on. On my system I get

$ readelf --dynamic --symbols --wide /usr/lib64/libreadline.so.7.0 | fgrep tputs
    17: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tputs

i.e. tputs is an external reference in the readline code.

EDIT: the library would be libtinfo:

$ readelf --dynamic --symbols --wide /usr/lib64/libtinfo.so.6 | fgrep tputs
   199: 0000000000019a30   151 FUNC    GLOBAL DEFAULT   12 tputs
   245: 00000000000195f0   930 FUNC    GLOBAL DEFAULT   12 tputs_sp

So the solution would be to use -lreadline -ltinfo.

In general I would suggest not to compile libraries yourself, but instead install the -dev(el) packages provided by your Linux distribution. Then you can use e.g. pkg-config command to automatically discover the correct C flags and linker options for a library.

like image 107
Stefan Becker Avatar answered Mar 07 '23 03:03

Stefan Becker