5

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.

Yunbin Liu
  • 1,484
  • 2
  • 11
  • 20
  • Your question shows how you build `readline` but the error message is from building your code where you want to link against `libreadline`. You should add the command line that throws the error. – Stefan Becker Jan 27 '19 at 12:41

1 Answers1

9

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.

Stefan Becker
  • 5,695
  • 9
  • 20
  • 30
  • 3
    I compile install library for avoid like [DELL_Hell](https://en.wikipedia.org/wiki/DLL_Hell), and now, I find use `-lreadline -ltinfo` or `-lreadline -ltermcap` or `-lreadline -lncurses` all could work, thanks. – Yunbin Liu Jan 27 '19 at 17:03
  • Suppose I still want to compile libraries myself and I see that there is a symbol table entry that references an UNDEF symbol. How do I find out which object module that external symbol is defined in? Is there something in that readelf output that tells you that `tputs` is defined in the `libtinfo` library? – Nicholas Cousar Jan 24 '22 at 11:39
  • @NicholasCousar you can look at the list of shared libraries that are required by a binary and are used to resolve undefined symbols on loading it. For the given example it would be `readelf --dynamic --wide /usr/lib64/libreadline.so.7.0 | fgrep Shared`. It would print out something like `Shared library: [libtinfo.so.6]` – Stefan Becker Jan 25 '22 at 12:32