Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGW support? #117

Closed
Berrysoft opened this issue Feb 17, 2020 · 4 comments
Closed

MinGW support? #117

Berrysoft opened this issue Feb 17, 2020 · 4 comments
Labels
feature-request New feature or request

Comments

@Berrysoft
Copy link

WIL library is not compatible with MinGW(-W64) now, mostly because of gcc, which doesn't recognize some non-standard syntax. I also tried clang for mingw-w64, but it gave different errors.

test file:

#include <wil/result.h>

int main()
{
    return 0;
}

g++:
It is too long, and is attached as file.
gcc.log

clang++:

In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
In file included from C:\msys64\mingw64\include\wil/result_macros.h:17:
C:\msys64\mingw64\include\wil/common.h:261:1: error: C++ requires a type specifier for all declarations
WI_ODR_PRAGMA("WIL_KERNEL_MODE", "0")
^
C:\msys64\mingw64\include\wil/common.h:256:37: note: expanded from macro 'WI_ODR_PRAGMA'
#define WI_ODR_PRAGMA(NAME, TOKEN)  __pragma(detect_mismatch("ODR_violation_" NAME "_mismatch", TOKEN))
                                    ^
C:\msys64\mingw64\include\wil/common.h:261:1: error: use of undeclared identifier 'detect_mismatch'
C:\msys64\mingw64\include\wil/common.h:256:46: note: expanded from macro 'WI_ODR_PRAGMA'
#define WI_ODR_PRAGMA(NAME, TOKEN)  __pragma(detect_mismatch("ODR_violation_" NAME "_mismatch", TOKEN))
                                             ^
C:\msys64\mingw64\include\wil/common.h:470:6: error: linker pragma must include g_header_init variation
    #error linker pragma must include g_header_init variation
     ^
C:\msys64\mingw64\include\wil/common.h:261:38: error: expected ';' after top level declarator
WI_ODR_PRAGMA("WIL_KERNEL_MODE", "0")
                                     ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:93:1: error: C++ requires a type specifier for all declarations
WI_ODR_PRAGMA("WIL_AllocateMemory", "1")
^
C:\msys64\mingw64\include\wil/common.h:256:37: note: expanded from macro 'WI_ODR_PRAGMA'
#define WI_ODR_PRAGMA(NAME, TOKEN)  __pragma(detect_mismatch("ODR_violation_" NAME "_mismatch", TOKEN))
                                    ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:93:1: error: use of undeclared identifier 'detect_mismatch'
C:\msys64\mingw64\include\wil/common.h:256:46: note: expanded from macro 'WI_ODR_PRAGMA'
#define WI_ODR_PRAGMA(NAME, TOKEN)  __pragma(detect_mismatch("ODR_violation_" NAME "_mismatch", TOKEN))
                                             ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:93:41: error: expected ';' after top level declarator
WI_ODR_PRAGMA("WIL_AllocateMemory", "1")
                                        ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
In file included from C:\msys64\mingw64\include\wil/result_macros.h:123:
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:129:30: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
                             ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:131:32: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                               ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:131:105: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                                                                                                        ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:133:31: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy);
                              ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:135:33: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                                ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:135:123: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                                                                                                                          ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:137:29: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
                            ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:139:31: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                              ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:139:104: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                                                                                                       ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:141:30: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend);
                             ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:143:32: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                               ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\strsafe.h:143:124: error: unknown type name 'STRSAFE_LPSTR'
STRSAFEAPI StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags);
                                                                                                                           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
@sylveon
Copy link
Contributor

sylveon commented Feb 17, 2020

This library builds when Clang runs in MSVC compatibility mode. Building from mingw doesn't uses the MSVC compatibility mode.

@Berrysoft
Copy link
Author

@sylveon This library builds when Clang runs in MSVC compatibility mode.

That's right when building with Microsoft Windows SDK, but not with Windows SDK shipped with MinGW, because wil uses some features provided by official Windows SDK.

Build command line:

$ clang++ test.cpp -fms-extensions -fms-compatibility -fms-compatibility-version=19.14 -D_M_AMD64 -D__GNUC__

Output:

In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
In file included from C:\msys64\mingw64\include\wil/result_macros.h:124:
In file included from C:\msys64\mingw64\lib\clang\9.0.0\include\intrin.h:12:
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:266:36: error: expected unqualified-id
    __MACHINE(char *__cdecl strcat(char *,const char *))
                                   ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:266:36: error: expected ')'
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:266:35: note: to match this '('
    __MACHINE(char *__cdecl strcat(char *,const char *))
                                  ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:268:36: error: expected unqualified-id
    __MACHINE(char *__cdecl strcpy(char * __restrict__ ,const char * __restrict__ ))
                                   ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:268:36: error: expected ')'
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:268:35: note: to match this '('
    __MACHINE(char *__cdecl strcpy(char * __restrict__ ,const char * __restrict__ ))
                                  ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:272:43: error: expected unqualified-id
    __MACHINEIW64(wchar_t *__cdecl wcscat(wchar_t * __restrict__ ,const wchar_t * __restrict__ ))
                                          ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:272:43: error: expected ')'
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:272:42: note: to match this '('
    __MACHINEIW64(wchar_t *__cdecl wcscat(wchar_t * __restrict__ ,const wchar_t * __restrict__ ))
                                         ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:274:43: error: expected unqualified-id
    __MACHINEIW64(wchar_t *__cdecl wcscpy(wchar_t * __restrict__ ,const wchar_t * __restrict__ ))
                                          ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:274:43: error: expected ')'
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:274:42: note: to match this '('
    __MACHINEIW64(wchar_t *__cdecl wcscpy(wchar_t * __restrict__ ,const wchar_t * __restrict__ ))
                                         ^
C:\msys64\mingw64\x86_64-w64-mingw32\include\intrin.h:186:23: note: expanded from macro '__MACHINEIW64'
#define __MACHINEIW64 __MACHINE
                      ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:1176:149: error: unknown type name '_Post_z_'
        __declspec(selectany) void(__stdcall *g_pfnGetContextAndNotifyFailure)(_Inout_ FailureInfo *pFailure, _Out_writes_(callContextStringLength) _Post_z_ PSTR callContextString, _Pre_satisfies_(callContextStringLength > 0) size_t callContextStringLength) WI_PFN_NOEXCEPT = nullptr;
                                                                                                                                                    ^
C:\msys64\mingw64\include\wil/result_macros.h:1176:163: error: expected ')'
        __declspec(selectany) void(__stdcall *g_pfnGetContextAndNotifyFailure)(_Inout_ FailureInfo *pFailure, _Out_writes_(callContextStringLength) _Post_z_ PSTR callContextString, _Pre_satisfies_(callContextStringLength > 0) size_t callContextStringLength) WI_PFN_NOEXCEPT = nullptr;
                                                                                                                                                                  ^
C:\msys64\mingw64\include\wil/result_macros.h:1176:79: note: to match this '('
        __declspec(selectany) void(__stdcall *g_pfnGetContextAndNotifyFailure)(_Inout_ FailureInfo *pFailure, _Out_writes_(callContextStringLength) _Post_z_ PSTR callContextString, _Pre_satisfies_(callContextStringLength > 0) size_t callContextStringLength) WI_PFN_NOEXCEPT = nullptr;
                                                                              ^
C:\msys64\mingw64\include\wil/result_macros.h:1363:90: error: unknown type name '_Post_z_'
                               bool fWantDebugString, _Out_writes_(debugStringSizeChars) _Post_z_ PWSTR debugString, _Pre_satisfies_(debugStringSizeChars > 0) size_t debugStringSizeChars,
                                                                                         ^
C:\msys64\mingw64\include\wil/result_macros.h:1363:105: error: expected ')'
                               bool fWantDebugString, _Out_writes_(debugStringSizeChars) _Post_z_ PWSTR debugString, _Pre_satisfies_(debugStringSizeChars > 0) size_t debugStringSizeChars,
                                                                                                        ^
C:\msys64\mingw64\include\wil/result_macros.h:1362:31: note: to match this '('
        inline void LogFailure(__R_FN_PARAMS_FULL, FailureType type, HRESULT hr, _In_opt_ PCWSTR message,
                              ^
C:\msys64\mingw64\include\wil/result_macros.h:1513:23: error: no type named 'InterlockedIncrementNoFence' in the global namespace
                    ::InterlockedIncrementNoFence(m_pCopy);
                    ~~^
C:\msys64\mingw64\include\wil/result_macros.h:1548:27: error: no member named 'InterlockedIncrementNoFence' in the global namespace
                        ::InterlockedIncrementNoFence(&m_pCopy->m_refCount);
                        ~~^
C:\msys64\mingw64\include\wil/result_macros.h:1571:27: error: no member named 'InterlockedIncrementNoFence' in the global namespace
                        ::InterlockedIncrementNoFence(&m_pCopy->m_refCount);
                        ~~^
C:\msys64\mingw64\include\wil/result_macros.h:1678:22: error: no member named 'InterlockedIncrementNoFence' in the global namespace; did you mean '_InterlockedIncrement'?
            return ::InterlockedIncrementNoFence(&s_cErrorCount);
                   ~~^
C:\msys64\mingw64\x86_64-w64-mingw32\include\psdk_inc/intrin-impl.h:1502:10: note: '_InterlockedIncrement' declared here
__LONG32 _InterlockedIncrement(__LONG32 volatile *Addend);
         ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:1686:22: error: no member named 'InterlockedIncrementNoFence' in the global namespace; did you mean '_InterlockedIncrement'?
            return ::InterlockedIncrementNoFence(&s_cErrorCount);
                   ~~^
C:\msys64\mingw64\x86_64-w64-mingw32\include\psdk_inc/intrin-impl.h:1502:10: note: '_InterlockedIncrement' declared here
__LONG32 _InterlockedIncrement(__LONG32 volatile *Addend);
         ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:1694:22: error: no member named 'InterlockedIncrementNoFence' in the global namespace; did you mean '_InterlockedIncrement'?
            return ::InterlockedIncrementNoFence(&s_cErrorCount);
                   ~~^
C:\msys64\mingw64\x86_64-w64-mingw32\include\psdk_inc/intrin-impl.h:1502:10: note: '_InterlockedIncrement' declared here
__LONG32 _InterlockedIncrement(__LONG32 volatile *Addend);
         ^
In file included from test.cpp:1:
In file included from C:\msys64\mingw64\include\wil/result.h:16:
C:\msys64\mingw64\include\wil/result_macros.h:1842:17: error: use of undeclared identifier 'ERROR_ASSERTION_FAILURE'
                WI_USAGE_ERROR_FORWARD("CALLER BUG: Macro usage error detected.  GetLastError() does not have an error.");
                ^
C:\msys64\mingw64\include\wil/result_macros.h:875:138: note: expanded from macro 'WI_USAGE_ERROR_FORWARD'
#define WI_USAGE_ERROR_FORWARD(msg, ...)                    do { ReportFailure_Hr<FailureType::Log>(__R_FN_CALL_FULL, HRESULT_FROM_WIN32(ERROR_ASSERTION_FAILURE)); WI_USAGE_ASSERT_STOP(false); } while ((void)0, 0)
                                                                                                                                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

@dunhor
Copy link
Member

dunhor commented Feb 18, 2020

I'm not personally all that familiar with MinGW, but I'll try and speak to what I can.

  1. Compiler feature support
    As has been pointed out, there's currently a pretty heavy reliance on MSVC features. So MSVC will obviously work and Clang in MSVC-compat mode should work (and is tested to a reasonable degree). There is the occasional ask that some subset of WIL be usable on Linux, so at least as far as making WIL more aware of different compiler features, I'd probably group this ask under that blanket. The status of that ask, however, is that nobody has been willing to dedicate enough time to making such an update at an acceptable level of quality. What generally ends up happening is that the subsets of features that are needed are stripped out and stripped down until it works. I'm not currently aware of any current or future plans to address this.

  2. Windows SDK
    There is, and probably always will be, the assumption that a given SDK version implies a set of features/definitions. In addition, there's a "minimum" SDK version where features/definitions are assumed to exist without the need to surround usage with version check macros (the exact version is unknown to me; it's a moving target, though we've been better about not bumping it without good reason). In either case, if the SDK version is said to be or assumed to be some value, then the features in that SDK are free game. E.g. the error about _Post_z_ seems to indicate that either the effective SDK version is too low, or the contents of the sal.h equivalent are incomplete. It could also be the case that there's a missing include, which is simple to fix.

@jonwis
Copy link
Member

jonwis commented Nov 16, 2023

Closing for now as we do not have the expertise to support MinGW. We welcome a pull request from someone who can make the appropriate changes. If there are Windows PSDK header changes that would make this easier please include them when you send the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants