UTF8 is not working with MSYS2 Mingw64 UCRT compiler
Description / Steps to reproduce the issue
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.
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
Expected behavior
it should read the file and print File opened successfully
Actual behavior
when I run it in Windows 7 I get: Error opening file: Invalid argument
Verification
- [x] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)
Windows Version
MINGW64_NT-6.1-7601-WOW64
Are you willing to submit a PR?
No response
I'm not sure this can work on Windows 7. Also, not sure about that. But I think you'd need to link with a manifest to indicate that your application should use UTF-8: https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page
@mmuetzel it seems that the manifest works with newer windows only 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.
it seems that the manifest works with newer windows only
Exactly. That's why I wrote that I'm not sure this can work on Windows 7.
Can we close this?
@oltolm UTF8 and UCRT works fine if i compile with visual studio in windows 7, so it is not a problem of windows 7, this needs to be fixed in mingw I think and hope
@badrelmers what it's saying is you need to static link ucrt for this to work, which for "mingw" is currently not possible. It is not clear if Microsoft's license allows this or not and there do seem to be some UCRT sources published as MIT https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource But it does say "Subset" so it might not be useful.
@Peter0x44 yes I see, thank you. please do you know a working way to link statically with UCRT in Mingw?