3

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:

  1. Native Linux compilation: gcc test.c -o test && ./test
  2. Winegcc compilation: winegcc test.c o test.exe && ./test.exe
  3. MinGW64 compilation when the output is not a terminal : 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:

  1. MinGW64 compilation when the output is a terminal: 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:

  1. system("chcp 65001"); — same output (the chcp command succeeds).
  2. x86_64-w64-mingw32-gcc -fexec-charset=utf8 -finput-charset=utf8 — same output.
  3. SetConsoleOutputCP(CP_UTF8); — same output.
  4. wineconsole cmd and run .\test from there — same output.
  5. LANG=en_US.UTF-8 wine ./test.exe — same output.
  6. _setmode(_fileno(stdout), _O_U8TEXT); — no output at all.
  7. Most combinations of the above — no dice.

What I have not tried yet:

  1. Compiling with a Microsoft compiler under Wine.
  2. Compiling with MinGW under Wine.
  3. Compiling and/or running the program under real Windows with either compiler.

How can I fix the non-working case?

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • 2
    Character encoding is a PITA on Windows. Concerning compiling with a M$ compiler on Wine: By personal experience I know that you cannot install such a compiler, Wine is not accepted as base OS, the installation fails. -- I tried MinGW for Windows on Wine, and it produces the same result like yours. – the busybee Jul 31 '22 at 19:30
  • 1
    Compiling with MinGW on native Win10 and running in CMD works, if `chcp 65001` is used. – the busybee Aug 01 '22 at 14:07

0 Answers0