0

I try to check the output of the get_wch function from the ncurses library, on Archlinux install.

But when I call the function, I got this GCC error:

main.c:6:15: warning: implicit declaration of function "get_wch";

I linked the lib like my GCC command-line suggest:

gcc main.c -lncursesw -o exec

I have also check that ncurses is installed:

core/ncurses 6.2-1 [installed]
multilib/lib32-ncurses 6.2-1 [installed]

And I see the header generated at the lib compile time that allow me to use "widec" functions, when I list header files in the "usr/include" directory.

#include <curses.h>

int main() {
    initscr();
    int test = 0;
    int result = get_wch(&test);
    printf("Caractère : {} / Function code : {}\n", test, result);
    endwin();
return 0;
}

I don't understand how to use this lib. And the available "documentation" seems to play against me...

Apitronix
  • 305
  • 2
  • 13

1 Answers1

1

The gcc warning

main.c:6:15: warning: implicit declaration of function "get_wch";

tells you that there is no function prototype for get_wch. X/Open Curses specified all of the wide-character functions conditionally (to avoid breaking old programs). That's summarized in the ncurses manual page:

You must also enable the wide-character features in the header file when compiling for the wide-character library to use the extended (wide-character) functions. The symbol which enables these features has changed since XSI Curses, Issue 4:

  • Originally, the wide-character feature required the symbol _XOPEN_SOURCE_EXTENDED but that was only valid for XPG4 (1996).

  • Later, that was deemed conflicting with _XOPEN_SOURCE defined to 500.

  • As of mid-2018, none of the features in this implementation require a _XOPEN_SOURCE feature greater than 600. However, X/Open Curses, Issue 7 (2009) recommends defining it to 700.

  • Alternatively, you can enable the feature by defining NCURSES_WIDECHAR with the caveat that some other header file than curses.h may require a specific value for _XOPEN_SOURCE (or a system-specific symbol).

The prototype for get_wch uses wint_t (an integer which can hold a "wide character" such as Unicode). The manual page lists these types which are used in the wide-character ncursesw library (and function prototypes): cchar_t, wchar_t and wint_t

If you want to use a function prototype using any of those types, your program should turn on the feature. As mentioned before, defining NCURSES_WIDECHAR is simplest.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105