ned14 / status-code

Proposed SG14 status_code for the C++ standard
Other
64 stars 13 forks source link

Windows GNU ABI / MINGW support #32

Open mizvekov opened 3 years ago

mizvekov commented 3 years ago

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.

ned14 commented 3 years ago

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

mizvekov commented 3 years ago

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

jcelerier commented 8 months ago

On GCC it looks like

 __attribute__((alias("GetLastError")))

could work ?

jcelerier commented 8 months ago

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?)

ned14 commented 8 months ago

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.

jcelerier commented 8 months ago

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

ned14 commented 8 months ago

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.

jcelerier commented 8 months ago

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

ned14 commented 8 months ago

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

jcelerier commented 7 months ago

thanks, testing ASAP