What should I do if Ncurses shows Chinese garbled under Linux?

  

Ncurses is a library. The most used component is a form. In the operation of Linux system, many friends encounter Chinese garbled problems when using Ncurses. How to deal with this problem? The following small series will introduce you to the Chinese garbled solution when using Ncurses.

There are a few key points:

1.gcc compile-time use, gcc -lncursesw --verbose to see if support -lncursesw connection;

2. Code In the file, set locale

#include

#include

int main(int argc, char const *argv[])

{

setlocale(LC_ALL, “”);

initscr();

noecho();

refresh();

printw (“ I will test Chinese /n”);

getchar();

return 0;

}

3. Command line execution Apt-cache search libncursesw5, check whether the ncurses library is installed

Found that my linux does not support; found under /usr/include/ncurses.h

However, no one else said ncursesw directory ;

Later I found out that I installed libncurses5 and also installed libncursesw5, which caused the -lncursesw option to be unusable. I uninstalled libncurses5 and then reinstalled libncursesw5;

The specific command is

1. apt-cache search libncurses5

2. apt-get purge libncurses5

3. sudo apt-get purge libncurses5-dbg

4. sudo apt -get purge libncurses5-dev

5. sudo apt-get autoremove

6. sudo apt-get clean

7. dpkg -l | Grep ^rc| Awk ‘{print $2}’ | Xargs dpkg -P

Then install libncursesw5, the command is as follows

1. sudo apt-get install libncursesw5

2. sudo apt-get install libncursesw5-dbg

3. sudo apt-get install libncursesw5-dev

Then

gcc -c test.o test.c

gcc -o test test.o -lncursesw

Then run. /test

Found that Chinese can print normally

The above is the introduction of the Chinese garbled solution using Ncurses in Linux. If you have the same problem in the process of using it, If you don't know how to solve it, try the method described in this article.

Copyright © Windows knowledge All Rights Reserved