在linux上用mingw构建程序并在wine下运行---UTF-8支持

问题描述 投票:0回答:1

我有打印一些字符的 C 代码。我希望看到这些字符被打印出来,而不是字母汤,

#include <stdio.h>
int main() {
    const char* test = "Greek: αβγδ; German: Übergrößenträger";
    printf("%s\n", test);
}

什么有效:

  1. 原生Linux编译:
    gcc test.c -o test && ./test
  2. Winegcc编译:
    winegcc test.c o test.exe && ./test.exe
  3. MinGW64编译当输出不是终端时
    x86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe | cat

所有三个命令都会将

Greek: αβγδ; German: Übergrößenträger
打印到终端。

什么不起作用:

  1. MinGW64编译当输出为终端时
    x86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe

这会将

Greek: αβγδ; German: ÃbergröÃenträger
打印到终端。

看起来 MinGW 运行时检测输出是否是终端/控制台,并且做了完全错误的事情。

我尝试过的:

  1. system("chcp 65001");
    — 相同的输出(chcp 命令成功)。
  2. x86_64-w64-mingw32-gcc -fexec-charset=utf8 -finput-charset=utf8
    — 相同的输出。
  3. SetConsoleOutputCP(CP_UTF8);
    — 相同的输出。
  4. wineconsole cmd
    并从那里运行
    .\test
    — 相同的输出。
  5. LANG=en_US.UTF-8 wine ./test.exe
    — 相同的输出。
  6. _setmode(_fileno(stdout), _O_U8TEXT);
    — 根本没有输出。
  7. 上述大多数组合 - 没有骰子。

我还没有尝试过:

  1. 在 Wine 下使用 Microsoft 编译器进行编译。
  2. Wine 下使用 MinGW 编译。
  3. 使用任一编译器在真实 Windows 下编译和/或运行程序。

如何修复无法工作的情况?

c utf-8 mingw-w64 wine
1个回答
0
投票

我查了一下,被告知

wprintf()
通常适用于“宽”字符格式。 (例如,多于一个字节的字符格式)我通常不使用 C,所以我也很好奇如何强制 UTF-8 输出。

另外,来自

locale.h
的这个可能会有所帮助:

    // Set the console to support UTF-8 output
    _setmode(_fileno(stdout), _O_U8TEXT);

我希望这就是您正在寻找的(请不要对我大喊大叫)

© www.soinside.com 2019 - 2024. All rights reserved.