使用ncurses打印宽的unicode字符 [英] Print a wide unicode character with ncurses
问题描述
我正在尝试使用Ubuntu上C语言中的ncurses.h
库在屏幕上放置一个星标Unicode字符.我要运行的代码如下:
I'm trying to position a star unicode character on screen using the ncurses.h
library in C on Ubuntu. The code I'm trying to run is the following:
#include <stdio.h>
#include <wchar.h>
#include <curses.h>
#include <ncurses.h>
#include <stdlib.h>
#include <wctype.h>
#include <locale.h>
int main() {
setlocale(LC_CTYPE, "");
initscr();
cbreak();
WINDOW *win = newwin(0, 0, 0, 0);
refresh();
wrefresh(win);
const wchar_t* star = L"0x2605";
mvaddwstr(3, 3, star);
getch();
endwin();
}
但是我不断收到错误消息
But I keep getting the error
implicit declaration of function ‘mvaddwstr’ [-Wimplicit-function-declaration]
尽管此功能在此处以及我能做到的类似功能都得到了很好的证明.也不能上班.有没有我需要包括的图书馆来完成这项工作?还是有替代方法可以显示此角色?感谢您的帮助.
Despite this function being well documented here together with similar functions which I can't get to work either. Is there some library I'm not including to make this work? or is there an alternative way to go about displaying this character? I appreciate any help.
推荐答案
您必须针对窄"诅咒(ncurses与ncursesw)进行编译
You must be compiling against the "narrow" curses (ncurses vs ncursesw)
我能够使用以下代码在ubuntu 16.04上编译您的示例:
I was able to compile your example on ubuntu 16.04 with the following:
apt install libncursesw5-dev
# --cflags expanded to: -D_GNU_SOURCE -I/usr/include/ncursesw
gcc main.c $(ncursesw5-config --cflags) -c
# --libs expanded to: -lncursesw -ltinfo
gcc main.o $(ncursesw5-config --libs) -o main
然后
./main
我还必须对您的示例代码进行以下区分:
I had to make the following diff to your example code as well:
- const wchar_t* star = L"0x2605";
+ const wchar_t* star = L"\x2605";
这篇关于使用ncurses打印宽的unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!