Curses library doesn't support wide char on OS X high sierra

て烟熏妆下的殇ゞ 提交于 2019-12-11 03:07:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/48042203/curses-library-doesnt-support-wide-char-on-os-x-high-sierra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!