I have C code that prints some characters. I would like to see these characters printed, as opposed to an alphabet soup,
#include <stdio.h>
int main() {
const char* test = "Greek: αβγδ; German: Übergrößenträger";
printf("%s\n", test);
}
What works:
gcc test.c -o test && ./test
winegcc test.c o test.exe && ./test.exe
x86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe | cat
All three commands print Greek: αβγδ; German: Übergrößenträger
to the terminal.
What doesn't work:
x86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe
This prints Greek: αβγδ; German: ÃbergröÃenträger
to the terminal.
It looks like the MinGW runtime detects if the output is a terminal/console, and does exactly the wrong thing.
What I have tried:
system("chcp 65001");
— same output (the chcp command succeeds).x86_64-w64-mingw32-gcc -fexec-charset=utf8 -finput-charset=utf8
— same output.SetConsoleOutputCP(CP_UTF8);
— same output.wineconsole cmd
and run .\test
from there — same output.LANG=en_US.UTF-8 wine ./test.exe
— same output._setmode(_fileno(stdout), _O_U8TEXT);
— no output at all.What I have not tried yet:
How can I fix the non-working case?
I looked it up, and was told that wprintf()
usually works with "wide" character formats (e.g. more than one byte character formats). I don't usually use C so I was also curious about how you force a UTF-8 output.
Also, this from locale.h
might help:
// Set the console to support UTF-8 output
_setmode(_fileno(stdout), _O_U8TEXT);