Home > OS >  Where do I find the c readline library in ubuntu?
Where do I find the c readline library in ubuntu?

Time:11-29

I'm on Ubuntu 20.04.5 LTS and I've done:

sudo apt-get install libreadline6

Yet vs code doesn't recognize the #include <readline/readline.h> or #include <readline/history.h>

And calling make with:

-Wall -Wextra -Werror -g -lreadline

Gives me readline/readline.h: No such file or directory

What am I missing? Where is the library located?

CodePudding user response:

Install the development package: libreadline-dev. You've only installed the runtime package (and it does not include header files since those aren't needed in runtime).

$ sudo apt install libreadline-dev
...

Check what you got from the libreadline-dev package (the files you missed are marked with *):

$ dpkg -L libreadline-dev
/.
/usr
/usr/include
/usr/include/readline
/usr/include/readline/chardefs.h
/usr/include/readline/history.h                    *
/usr/include/readline/keymaps.h
/usr/include/readline/readline.h                   *
/usr/include/readline/rlconf.h
/usr/include/readline/rlstdc.h
/usr/include/readline/rltypedefs.h
/usr/include/readline/tilde.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libhistory.a
/usr/lib/x86_64-linux-gnu/libreadline.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/readline.pc
/usr/share
/usr/share/doc
/usr/share/info
/usr/lib/x86_64-linux-gnu/libhistory.so
/usr/lib/x86_64-linux-gnu/libreadline.so
/usr/share/doc/libreadline-dev

The output from pkg-config --cflags --libs readline will then give you the necessary include path options, defines and link options (taken from the file /usr/lib/x86_64-linux-gnu/pkgconfig/readline.pc listed above). Possible output:

$ pkg-config --cflags --libs readline
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -lreadline

Then compile and link:

$ gcc $(pkg-config --cflags --libs readline) -lhistory -Wall -Wextra ...
  • Related