Menu

#203 Why UTF8 is not working with MSYS2 Mingw64 UCRT compiler?

v1.0 (example)
open
nobody
UCRT (1)
5
2025-06-26
2025-06-26
alkor san
No

I see in multiple places things like that:

UCRT (ucrtbase.dll): Supports UTF-8 in paths, if you enable a UTF-8 locale
in your application.

here and here

I tested with this:

#include <stdio.h>
#include <locale.h>

int main() {
    setlocale(LC_ALL, "en_US.UTF-8"); // Set locale to UTF-8
    FILE *fp = fopen("test_utf8_文件.txt", "r");  
    if (fp) {
        printf("File opened successfully\n");
        fclose(fp);
    } else {
        perror("Error opening file");
    }
    return 0;
}

I compiled it with UCRT64 of Mingw64 of MSYS2 in Windows 7, when I run it
in Windows 7 I get: Error opening file: Invalid argument

I also tested i686-15.1.0-release-win32-dwarf-ucrt-rt_v12-rev0 from
https://github.com/niXman/mingw-builds-binaries

does this work in older windows versions like windows 7 or do I need win
10+?

Microsoft says:

To use this feature on an OS prior to Windows 10, you must use app-local
deployment or link statically using version 1803 (10.0.17134.0) of the
Windows SDK or later. For Windows 10 operating systems prior to 1803
(10.0.17134.0), only static linking is supported.

but in Mingw64 I find no way to link UCRT statically!

is there any hope to make this work in windows 7?

Discussion


Log in to post a comment.

MongoDB Logo MongoDB