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

Windows GNU ABI / MINGW support #32

Open
mizvekov opened this issue May 24, 2021 · 10 comments
Open

Windows GNU ABI / MINGW support #32

mizvekov opened this issue May 24, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@mizvekov
Copy link

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 ned14 transferred this issue from ned14/outcome May 28, 2021
@ned14 ned14 added the bug Something isn't working label May 28, 2021
@ned14
Copy link
Owner

ned14 commented May 28, 2021

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

@mizvekov
Copy link
Author

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

@jcelerier
Copy link
Contributor

jcelerier commented Mar 6, 2024

On GCC it looks like

 __attribute__((alias("GetLastError")))

could work ?

@jcelerier
Copy link
Contributor

jcelerier commented Mar 6, 2024

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
Copy link
Owner

ned14 commented Mar 6, 2024

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
Copy link
Contributor

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

@ned14
Copy link
Owner

ned14 commented Mar 6, 2024

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
Copy link
Contributor

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

ned14 added a commit that referenced this issue Mar 12, 2024
@ned14
Copy link
Owner

ned14 commented Mar 12, 2024

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

@jcelerier
Copy link
Contributor

thanks, testing ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants