Skip to content

configure doesn't disable ncurses extended_pair_content() if ncursesw is not available #123925

Closed

Description

@madscientist

Bug report

Bug description:

On a system I'm trying to build Python for, I have libncurses.so available but not libncursesw.so.

Unfortunately, although this is not documented directly anywhere I can find, the ncurses extended_pair_content() and extended_color_content() functions (and the init_extended_*() functions) are not available in libncurses, they are only available in libncursesw. This causes the compilation of Python to fail:

checking for curses.h... yes
checking for ncurses.h... yes
checking for ncursesw... no
checking for initscr in -lncursesw... no
checking for ncurses... no
checking for initscr in -lncurses... yes
checking curses module flags... ncurses (CFLAGS: , LIBS: -lncurses)
checking for panel.h... yes
checking for panel... no
checking for update_panels in -lpanel... yes
checking panel flags... panel (CFLAGS: , LIBS: -lpanel)
checking for term.h... yes
checking whether mvwdelch is an expression... yes
checking whether WINDOW has _flags... yes
checking for curses function is_pad... yes
checking for curses function is_term_resized... yes
checking for curses function resize_term... yes
checking for curses function resizeterm... yes
checking for curses function immedok... yes
checking for curses function syncok... yes
checking for curses function wchgat... yes
checking for curses function filter... yes
checking for curses function has_key... yes
checking for curses function typeahead... yes
checking for curses function use_env... yes
  ...
checking for stdlib extension module _curses... yes
checking for stdlib extension module _curses_panel... yes
  ...
86_64-rl84-linux-gnu-gcc -pthread -shared      Modules/_cursesmodule.o -lncurses  -o Modules/_curses.cpython-312-x86_64-linux-gnu.so
  ...
./python -E -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%
d" % (get_platform(), *sys.version_info[:2]))' >platform
[ERROR] _curses failed to import: /data/src/python3/Linux-Release-make/bld.python3/build/lib.linux-x86_64-3.12/_curses.cpython-312-x86_64-linux-gnu.so: undefined symbol: extended_pair_content

If I try a simple program:

#include <ncurses.h>
#include <stdio.h>

int main(void)
{
    initscr();
    start_color();
    {
        int f, b;
        int r = extended_pair_content(1, &f, &b);

        printf("r=%d f=%d b=%d\n", r, f, b);
    }
    endwin();
    return 0;
}

then it works if I link with -lncursesw:

$ gcc -o /tmp/foo /tmp/foo.c -lncursesw
$

But fails if I only link with -lncurses:

$ gcc -o /tmp/foo /tmp/foo.c -lncurses
/bin/ld: /tmp/cccHNZsN.o: in function `main':
foo.c:(.text+0x85): undefined reference to `extended_pair_content'
/bin/ld: foo.c:(.text+0x107): undefined reference to `extended_color_content'
collect2: error: ld returned 1 exit status
$

I believe this patch will fix it:

--- a/Modules/_cursesmodule.c   2024-09-06 15:03:47.000000000 -0400
+++ b/Modules/_cursesmodule.c   2024-09-10 17:41:55.124440110 -0400
@@ -139,7 +139,7 @@
 #define STRICT_SYSV_CURSES
 #endif

-#if NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >= 20170401
+#if HAVE_NCURSESW && NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >\
= 20170401
 #define _NCURSES_EXTENDED_COLOR_FUNCS   1
 #else
 #define _NCURSES_EXTENDED_COLOR_FUNCS   0

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Activity

  1. serhiy-storchaka commented on Sep 11, 2024

    @serhiy-storchaka
    Member

    What is the value of NCURSES_EXT_FUNCS and NCURSES_EXT_COLORS? How is extended_pair_content defined in the header file on your system (if it is)?

  2. madscientist commented on Sep 11, 2024

    @madscientist
    Author

    The definition of these in curses.h appears thusly:

    #if 1
    #undef NCURSES_EXT_COLORS
    #define NCURSES_EXT_COLORS 20180224
        int         ext_color;      /* color pair, must be more than 16-bits */
    #endif
      ...
    /*
     * These functions are extensions - not in X/Open Curses.
     */
    #if 1
    #undef  NCURSES_EXT_FUNCS
    #define NCURSES_EXT_FUNCS 20180224
      ...
    extern NCURSES_EXPORT(int) extended_color_content(int, int *, int *, int *);
    extern NCURSES_EXPORT(int) extended_pair_content(int, int *, int *);
      ...
    extern NCURSES_EXPORT(int) init_extended_color(int, int, int, int);
    extern NCURSES_EXPORT(int) init_extended_pair(int, int, int);
    

    Just to note, this is by no means some bizarre custom version of Linux. This is Red Hat Enterprise Linux 8.6. The only unusual thing is that the ncursesw library is not present.

    Also I see the same problem on Ubuntu 20.04, which has this version:

    #define NCURSES_EXT_COLORS 20200212
    #define NCURSES_EXT_FUNCS 20200212
    

    Right now I don't have a newer system but I can try at home later with Ubuntu 24.04 LTS.

  3. esaaprillia commented on Dec 11, 2024

    @esaaprillia

    same problem when cross compiling and building a static python3 host

    Error:  _curses failed to import: /home/build_dir/hostpkg/Python-3.13.1/build/lib.linux-x86_64-3.13/_curses.cpython-313-x86_64-linux-gnu.so: undefined symbol: extended_color_content
    Error:  _curses_panel failed to import: PyCapsule_Import could not import module "_curses"
    Error:  readline failed to import: /home/build_dir/hostpkg/Python-3.13.1/build/lib.linux-x86_64-3.13/readline.cpython-313-x86_64-linux-gnu.so: undefined symbol: UP
    The following modules are
    
  4. added 2 commits that reference this issue on Jan 2, 2025
  5. added 2 commits that reference this issue on Jan 2, 2025
  6. added 2 commits that reference this issue on Jan 2, 2025
  7. added a commit that references this issue on Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions