On Thu, 10 Oct 2024, LIU Hao wrote:

在 2024-10-10 20:27, Martin Storsjö 写道:
So I guess this is fine, as a consistency extension on what we already have.

It's a bit unclear to me what the real issue in https://github.com/mingw-w64/mingw-w64/issues/60 is though, and how this fixes it, because those macros are still going to be unavailable now - they're just unavailable in a more clear way now.

I.e. patch ok with me, but root issue is unclear.

Thanks. Pushed now.

With this applied, someone who wishes to call these functions will have to define `__MSVCRT_VERSION__` to at least 0x800 and bear the risk that their program no longer runs on XP, or they will have to define `__MSVCRT_VERSION__` to 0xA00 and link against MSVCR100 for example. Either way, for MSVCRT we define it to be 0x700 in 'mingw-w64-headers/configure.ac' and these shouldn't be declared.

Actually, the very issue I mentioned above turned out to bite me, sooner than I had expected.

The patch you pushed broke building of libc++ for msvcrt.dll.

libc++ uses _iswlower_l when targeting Windows - which now is undeclared. libc++ on Windows only targets Windows 7 and newer, so the fact that these functions are unavailable in msvcrt.dll on Windows XP (and Vista) is not an issue.

However we can't add -D__MSVCRT_VERSION__=0x800 when building libc++ to mitigate this. libc++ uses _strftime_l if building with a new enough CRT [1] [2]; this function is available since msvcr80.dll - but it is not available in any version of msvcrt.dll. So pretending that msvcrt.dll has the same features as msvcr80.dll breaks here - if we add this define, we suddenly run into a undefined reference to _strftime_l.

I wonder if the right solution here would be to amend the __MSVCRT_VERSION__ checks with checks for _WIN32_WINNT; if _WIN32_WINNT is set to a new enough version, declarations are visible for functions that only exist in new enough versions. And if you want to target older versions, just don't call those functions (and define _WIN32_WINNT to a lower version if you want to get the errors for it early enough).

I.e. instead of what we currently have,

    #if __MSVCRT_VERSION__ >= 0x800

We could have:

    #if __MSVCRT_VERSION__ >= 0x800 || _WIN32_WINNT >= 0x0600

I think this would fix the issue with libc++ for msvcrt.dll targets for me.

This isn't ideal, if targeting older numbered msvcr DLLs or crtdll.

    #if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)

This is slightly better, but we still can't distinguish between msvcr70.dll and msvcrt.dll though, but perhaps this is good enough?

What do you think?

// Martin

[1] 
https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/libcxx/include/__locale_dir/locale_base_api/win32.h#L222-L226
[2] 
https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/libcxx/src/support/win32/locale_win32.cpp#L127-L132

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to