_WIN32_WINNT redefined?

Eli Zaretskii eliz@gnu.org
Wed Nov 2 12:50:57 GMT 2022


> Date: Wed, 02 Nov 2022 09:46:20 +0000
> From: niXman via Gdb <gdb@sourceware.org>
> 
> On 2022-11-02 08:44, niXman via Gdb wrote:
> > On 2022-11-02 08:21, niXman via Gdb wrote:
> 
> ok, I did a little research.
> 
> the `_WIN32_WINNT` is defined in `gdbsupport/common-defs.h` only, but 
> referenced in `gnulib/import/gettimeofdeay.c` and 
> `gnulib/import/stat-w32.c` only, but not directly because those files 
> include `windows,h` and `sdkdkver.h`. thus that `_WIN32_WINNT` define is 
> never used!

No, _WIN32_WINNT is referenced in a lot of w32api header files, which
use it to decide whether to expose function prototypes, data type
declarations, macros, etc.  In effect, the value of _WIN32_WINNT
determines the oldest version of MS-Windows which the program needs to
support, by hiding APIs that are not available on later versions --
this ensures the program doesn't use those later APIs unintentionally.

> so I think the best way is to remove that define completely.

No, that's wrong, because if you remove that, you will basically force
everyone who builds GDB for Windows to use the default value of
_WIN32_WINNT defined by the w32api headers.  And that default is not
necessarily what we want.

> ideas?

Find out why the current definition causes trouble in your build, then
we could discuss the correct solution that works for everyone.

In the original report you said:

> In file included from 
> mingw64/lib/gcc/x86_64-w64-mingw32/13.0.0/include/c++/mutex:45,
>                   from 
> ../src/gdb-11.2/gdbsupport/../gdbsupport/thread-pool.h:27,
>                   from ../src/gdb-11.2/gdbsupport/thread-pool.cc:24:
> mingw64/lib/gcc/x86_64-w64-mingw32/13.0.0/include/c++/bits/std_mutex.h:163:5: 
> error: '__gthread_cond_t' does not name a type; did you mean 
> '__gthread_once_t'?
>    163 |     __gthread_cond_t* native_handle() noexcept { return 
> &_M_cond; }
>        |     ^~~~~~~~~~~~~~~~
> ```
> 
> the problem is a consequence of the fact that `_WIN32_WINNT` is 
> redefined somewhere to another value that is less than necessary.
> but when I pass `-D_WIN32_WINNT=0x0601` for CFLAGS/CXXFLAGS - the 
> trouble is gone.

This doesn't explain why -D_WIN32_WINNT=0x0601 solves the problem.
Can you explain that in enough detail, and point to the relevant parts
of the headers?

In addition, you point to this place in common-defs.h:

  /* We don't support Windows versions before XP, so we define
     _WIN32_WINNT correspondingly to ensure the Windows API headers
     expose the required symbols.  */
  #if defined (__MINGW32__) || defined (__CYGWIN__)
  # ifdef _WIN32_WINNT
  #  if _WIN32_WINNT < 0x0501
  #   undef _WIN32_WINNT
  #   define _WIN32_WINNT 0x0501
  #  endif
  # else
  #  define _WIN32_WINNT 0x0501
  # endif
  #endif	/* __MINGW32__ || __CYGWIN__ */

This defines _WIN32_WINNT only if it wasn't already defined, or if it
was defined to a value smaller than 0x0501.  So why isn't _WIN32_WINNT
defined in your w32api headers?  It should be defined to some default
value, which was determined when the w32api headers were produced, and
I'm guessing that this default value should be 0x0601, in which case
the above preprocessor stuff should not redefine it.


More information about the Gdb mailing list