Is Ncurses in Ubuntu 20.4 incompatible with the version in 18.04

Viewed 3126

I have 2 curses apps that I originally built on ubuntu 18.04 - and both work fine there.

When I copied them over to a new 20.04 system and tried to run them, the loader said it couldn't find libncurses5.so. So I tried installing libncurses5 (plus the corresponding -dev package), and then the apps worked - and everything displayed normally. But then I rebuilt them on the 20.04 system, and while they were able find the library and run, they both displayed funny characters - and one of them didn't position stuff right.

I then removed the libncurses5 stuff I had installed, and rebuilt the apps again (against ncurses6, which is still installed). Now, one of the apps displays everything correctly, but the other still displays stuff wrong - and in the wrong positions. By the way, gcc was originally unable to find "curses.h" until I had installed the ncurses5 stuff - but it still finds it okay after having uninstalled ncurses5.

So, is ncurses6 incompatible with code written in the days of ncurses5? I would suspect I just have $TERM set wrong (it's xterm-256color - in an ssh session running from Konsole), but why would the one program work, but not the other - with the same $TERM setting?

2 Answers

ncurses provides multiple ABIs in the same distribution. Previously, the default ABI was 5, and now it's 6. libncurses5 provides the v5 ABI, and libncurses6 provides the v6 ABI. You cannot use a piece of software linked against a shared library with an incompatible ABI like this because the shared library paths differ across ABIs so people don't accidentally load the wrong one and break their programs.

If you want to run an existing program linked against ABI v5, then you need the libncurses5 package. You do not need the -dev package unless you are developing against that package. If you are recompiling an existing package, you should use libncurses-dev, which will build against the latest version of ncurses unless you are sure you need to build against the old version. That package will include the curses.h header.

If you want to specify the location of the curses header, you should do that wit angle brackets: #include <curses.h>. It is a system path, and it is definitely provided by libncurses-dev.

If your program is using the standard curses API that's in common use, then recompiling it for a new version of ncurses should not change anything. The ABI changes likely consisted of changing some internal structures which do not affect the display but may enable new terminal features. The behavior of the curses API is standardized and breaking changes would not be expected.

It's likely that your TERM setting is indeed the problem. If you're running in an SSH session on another computer, it's possible that the system you're running it on lacks that terminal definition as part of the standard set, and requires an additional package (on Debian and Ubuntu, ncurses-term) that includes more terminal definitions. You can try running infocmp xterm-256color on that system, assuming it's running ncurses, to see if you do have that terminal definition. It will print terminal info if you do, and an error if you don't.

If you're in a screen or tmux session, then xterm-256color would be the wrong terminal type, and screen-256color would be a better choice. Even if not, you may want to check your terminal settings for the type it's emulating, since some terminal emulators have support for multiple terminal types.

Fixed it. It turns out that the curses calls in the app that didn't work were in a library that I hadn't rebuilt on the 20.04 system. The app that worked had its curses code in local modules that were recompiled when I rebuilt it.

Once I rebuilt the library with the curses calls and relinked the 'broken' app, it's all working with ncurses6. False alarm. Sorry.

Related