[PATCH] D33082: Fix Libc++ build with MinGW64

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 20:29:22 PDT 2017

EricWF added a comment.

In https://reviews.llvm.org/D33082#765282, @bcraig wrote:

> I think that we generally shouldn't be giving functions names that are already claimed elsewhere (like mbsnrtowcs and wcsnrtombs).  It is my opinion that these should always be qualified as __libcpp_* symbols.  We can easily run into trouble if users also defined mbsnrtowcs.  They have just as much of a right to do so as we do.
> That being said, I think that's a change for a different changelist.

Agreed.  Libc++ shouldn't be stealing names it doesn't own, but fixing that is a separate change.

In https://reviews.llvm.org/D33082#765185, @martell wrote:

> > ! In https://reviews.llvm.org/D33082#764617, @EricWF wrote:
> >  Defining `_GNU_SOURCE` during the library build isn't enough, it's also has to be defined when people are using the headers,
> >  and in that case we must depend on the compiler to pre-define it. Is it important that MinGW not define `_GNU_SOURCE` by default?
> I'm not sure why this isn't the default, it could be some backwards compatibility with mingw.org.
>  I will ask kai the author and find out.
> > Also do you know why `asprintf` is declared by mingw-w64 but `vasprintf` isn't? At minimum I think we still need to declare `vasprintf` in the
> >  headers because we can't count on `_GNU_SOURCE` being defined before `<features.h>` is first included, but we should be able to omit
> >  the definition.
> I believe it is in stdio.h but behind the guard `__USE_MINGW_ANSI_STDIO`
>  You are currently picking up is msvc compatable asprintf and not gnu.
>  Defining this will give you the gnu versions of both `vasprintf`, `asprintf` and also the GNU printf format specifiers.
>  You should be able use this to build libcxx just don't declare it publicly

Libc++ uses `vasprintf` in the headers, so it's not just a matter of building the library with `_GNU_SOURCE`. 
Since we can't dependably define `_GNU_SOURCE` or `__USE_MINGW_ANSI_STDIO` in the headers we're 
eventually going to have to provide our own implementations under different names. But I would rather do that as a separate commit if that's OK.


More information about the cfe-commits mailing list