I am trying g_error("你好");
but got “??” not “你好”
My glib version is 2.84.3
Also this: Wrong error text · Issue #5 · LesBoys43/libeventemitter · GitHub
Looking into the code, glib detects the console charset as non UTF-8 and converts the error text to ASCII. In my case, glib-2.84.4
detects ANSI_X3.4-1968
as console character set.
$ ./a.out
** (process:97704): ERROR **: 08:54:59.023: ??
Trace/breakpoint trap (core dumped)
Overriding the charset using CHARSET
env variable (non standard) outputs correctly.
$ CHARSET="UTF-8" ./a.out
** (process:97741): ERROR **: 08:55:08.332: 你好
Trace/breakpoint trap (core dumped)
The correct solution is to use setlocale(LC_ALL, "")
as documented in man setlocale
On startup of the main program, the portable "C" locale is selected as default. A program may be made portable to all locales by calling:
setlocale(LC_ALL, "");
after program initialization. If locale is NULL, the current locale is only queried, not modified.
2 Likes