ned14 / status-code

Proposed SG14 status_code for the C++ standard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows GNU ABI / MINGW support

mizvekov opened this issue · comments

WIndows GNU ABI has different mangling than MSVC ABI, so the linker symbol aliases for GetLastError / FormatMessage etc don't work.

These aliases instead would work:

#if defined(__MINGW32__)
#if defined(__x86_64__)
#pragma comment(linker, "/alternatename:_ZN13system_error25win3212GetLastErrorEv=GetLastError")
#pragma comment(linker, "/alternatename:_ZN13system_error25win3214FormatMessageWEmPKvmmPwmPv=FormatMessageW")
#pragma comment(linker, "/alternatename:_ZN13system_error25win3219WideCharToMultiByteEjmPKwiPciPKcPi=WideCharToMultiByte")
#elif defined(__i386__)
#pragma comment(linker, "/alternatename:__ZN13system_error25win3212GetLastErrorEv@0=__imp__GetLastError@0")
#pragma comment(linker, "/alternatename:__ZN13system_error25win3214FormatMessageWEmPKvmmPwmPv@28=__imp__FormatMessageW@28")
#pragma comment(linker, "/alternatename:__ZN13system_error25win3219WideCharToMultiByteEjmPKwiPciPKcPi@32=__imp__WideCharToMultiByte@32")
#else
#error Unknown architecture
#endif
#else
...
#endif

The above is enough to get it working with clang/lld targeting MINGW64 / GNU ABI (which is only what I need personally).
GCC / ld however do not support neither the #pragma comment nor /alternatename, so a different strategy is needed there.

Thanks for this BR. I think it applies actually exclusively to status-code, not Outcome, so I moved it here.

Yeah you are right sorry, was using the single-header version which pulled everything :)

On GCC it looks like

 __attribute__((alias("GetLastError")))

could work ?

well, it does not seem like it works so far. @ned14 would it be reasonable to have a patch that replaces those by inlines which calls the winapi functions directly in the GCC / MinGW case ? (Also I'm curious about the rationale for this design altogether, what is the value added to the library ? Wouldn't it make sense to LoadLibrary these symbols instead to simplify this, as this is in the end what the windows linker is going to do more-or-less AFAIK?)

The intention is to avoid status code headers including windows headers.

I would be keen to continue to not include windows headers. TBH I no longer have easy access to a windows dev box, which has not helped me get around to installing mingw and getting this fixed.

hm, on which platform are you ? for this library the mingw packages on any linux distro would work

I didn't know Ubuntu had packages for mingw until now.

Boost has closed the change window for the beta release, when it opens I might see if I can find the time to close this issue.

thanks ! if you have any lead on how to fix this properly I can also look into it

Try this fix and let me know if it works for you. Those Linux mingw packages were very useful, thank you.

thanks, testing ASAP