Search code examples
c++linuxcompiler-errorsncurses

Undefined reference to new NCURSES 6.1 Functions (alloc_pair, reset_color_pairs)


I'm trying to use these functions in my code, but neither compile correctly. I get errors like undefined reference to 'alloc_pair' and collect2: error: ld returned 1 exit status. Other functions (newwin, printw) work fine. Both functions seem to be installed, by looking at manpages. I also checked the libncurses-dev changelog (with apt), and it lists a new upstream release at version 6.1 (which the GNU ncurses log shows as having those functions). How can I ensure it installs correctly?

uname -a returns:

Linux hostname 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

EDIT: I also use if checks to make sure I'm using ncurses 6.1. (With NCURSES_VERSION)


Solution

  • Ubuntu's ncurses packages only support ABI 5, which given that ABI 6 was standard in 2015, makes Ubuntu a little behind the curve.

    You need ABI 6 for the newer functions, as mentioned in the release notes:

    This release is designed to be source-compatible with ncurses 5.0 through 6.0; providing extensions to the application binary interface (ABI). Although the source can still be configured to support the ncurses 5 ABI, the intent of the release is to provide extensions to the ncurses 6 ABI:

    You could of course compile ncurses for yourself, or use some distribution which has upgraded to the current ABI, but that source-compatibility hints that other packagers may not have gotten up to date, either.