Issue
In Linux, how can I choose which ncurses library to build against when both V5 and V6 are installed?
Right now it defaults to V6 (the project is the same as when it was building to V5 before the upgrade from Debian Jessie to Buster).
TIA!!
Solution
Debian has several packages for ncurses (I find the bug-reporting links easier to navigate than the package-tracking). At the moment, buster is "oldstable". That has development packages for ABI 5 and 6:
- libncurses-dev
- libncursesw-dev
- libncurses5-dev
- libncursesw5-dev
Each of those has a package-page which includes a list of files for each architecture, e.g., this, and for example
/usr/lib/x86_64-linux-gnu/pkgconfig/form.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/formw.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/menu.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/menuw.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/ncurses++.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/ncurses++w.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/ncurses.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/ncursesw.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/panel.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/panelw.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/tic.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/tinfo.pc
Generally, the filename for the ".pc" files is useful as a parameter to pkg-config
, e.g.,
pkg-config --cflags --libs libncurses-dev
which prints the -I
, -D
, -L
and -l options you'd use in a makefile or script.
You don't have to search through the webpages for that;
dpkg -l | grep 'ncurses'
lists the package with "ncurses" in their name, and for the example shown
dpkg -L libncurses-dev | grep -F .pc
shows the pkg-config files.
In a command-line, I could do this:
gcc -c $(pkg-config --cflags libncurses-dev) foo.c
for just the compiler, or to compile/link:
gcc -o foo $(pkg-config --cflags --libs libncurses-dev) foo.c
The package also has the "*-config" scripts which give similar information, without using pkg-config
, e.g.,
/usr/bin/ncurses5-config
/usr/bin/ncurses6-config
/usr/bin/ncursesw5-config
/usr/bin/ncursesw6-config
In the Debian development packages, it appears that there are ".pc" files only for ABI 6. But the "-config" files are provided for both ABI 5 and 6. So you should be able to compile with ABI 5, e.g,.
gcc -c $(ncurses5-config --cflags libncurses-dev) foo.c
Answered By - Thomas Dickey Answer Checked By - Pedro (WPSolving Volunteer)