未定义对新 NCURSES 6.1 函数的引用(alloc_pair、reset_color_pairs)

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

我试图在我的代码中使用这些函数,但都无法正确编译。我收到 undefined reference to 'alloc_pair'collect2: error: ld returned 1 exit status 之类的错误。其他功能(newwin、printw)工作正常。通过查看联机帮助页,这两个功能似乎都已安装。我还检查了 libncurses-dev 变更日志(使用 apt),它列出了 6.1 版的新上游版本(GNU ncurses 日志显示具有这些功能)。我怎样才能确保它安装正确?

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

编辑:我还使用 if 检查来确保我使用的是 ncurses 6.1。 (有 NCURSES_VERSION)

Ubuntu 的 ncurses 包仅支持 ABI 5,鉴于 ABI 6 在 2015 中是标准的,这使得 Ubuntu 有点落后。

您需要 ABI 6 才能使用新功能,如 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:

您当然可以自己编译 ncurses,或者使用一些已经升级到当前 ABI 的发行版,但是源兼容性暗示其他打包程序可能也没有更新。