3

OS X 10.13.2 (high sierra).

I'm trying to write simple curses program with widechar support, but it appears, that default (pre-installed library) curses doesn't support widechar:

Simplest program example (from here):

#include <ncursesw/ncurses.h>
#include <locale.h>
#include <wchar.h>

int main() {
    setlocale(LC_ALL, "");
    initscr();
    wchar_t wstr[] = { 9474, L'\0' };
    mvaddwstr(0, 0, wstr);
    refresh();
    getch();
    endwin();
    return 0;
}

doesn't compile, gives error:

test.cpp:1:10: fatal error: 'ncursesw/ncurses.h' file not found

Tried to find in manual pages:

man addwstr says:

   #include <curses.h>

   int addwstr(const wchar_t *wstr);
   int addnwstr(const wchar_t *wstr, int n);
   int waddwstr(WINDOW *win, const wchar_t *wstr);
   int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
   int mvaddwstr(int y, int x, const wchar_t *wstr);
   int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
   int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
   int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);

As man page says, tried to include "curses.h" instead of "ncursesw/ncurses.h". Again compile error:

test.cpp:9:5: error: use of undeclared identifier 'mvaddwstr'; did you mean 'mvaddstr'?

Tried to find any widechar-related curses header in /usr/include. No result. Any suggestions?

Andrii Pyvovar
  • 153
  • 1
  • 6

1 Answers1

2

The second example (using <curses.h>) will work with MacOS if you use a command like this:

gcc -o foo -D_XOPEN_SOURCE_EXTENDED foo.c -lncurses

That is:

  • you have to turn on a definition to make the wide-character features visible (which you could see by reading the header file), and
  • the library name is "ncurses" (although it contains the wide-character functions).

Do

nm /usr/lib/libncurses.dylib | grep addwstr

to see this:

0000000000024c39 T _addwstr
0000000000024fba T _mvaddwstr
00000000000254ad T _mvwaddwstr
000000000002580c T _waddwstr

As of mid-2018, MacOS bundles only a very old ncurses library (5.7, released in 2008), and a correspondingly old terminal database. You can see that by

$ /usr/bin/tic -V
ncurses 5.7.20081102

Interestingly, the dynamic library's filename hints that it is really ncurses 5.4 (another 4 years older), but the compiled-in version shown by tic and the curses.h header file tell the actual version. As noted, that library contains the symbols which would be needed by the wide-character library. The name-distinction between ncurses and ncursesw libraries used for most systems predates ncurses 5.4 (again) by a few years, so Apple's configuration would be confusing to most developers.

For development you should consider using something more recent, e.g., MacPorts or homebrew. For those, the configuration details are readily available and (unsurprisingly) provide ncursesw libraries.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • I tried your method without luck. I included `` and ``, then compiled with `g++ -D_XOPEN_SOURCE_EXTENDED -lncurses test.cpp` but it still complains ```error: no matching function for call to 'waddnwstr'``` . Do you have any idea how to fix this? Am I missing something? – LotoLo Jun 03 '18 at 19:31
  • That should be **`-lncursesw`** – Thomas Dickey Jun 03 '18 at 20:02
  • I tried, but I am on macOs Sierra and there isn't any ncursesw library – LotoLo Jun 04 '18 at 20:57