-
Notifications
You must be signed in to change notification settings - Fork 514
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
Allow to have both WinMain and main defined on Windows #1167
Conversation
I wonder if it works to just remove all the FORCE defines and just always have both main() and WinMain() in the code (unless SOKOL_NO_ENTRY is defined which would remove both main() and WinMain()). Did you try that already? I'll need to tinker with this idea a bit, if it works I would prefer that since it removes a bit of configuration complexity. |
I did! That is what I did before I decided to make this PR. It worked fine on my machines, Windows 10/Windows 11 were tested at the time. Only concern I can think is that maybe existing systems depend on the existence of either, not both and are therefore configured on that. Defining both would break this very hypothetical case. Oh, and the subsystem has to be explicitly defined: Lines 2188 to 2194 in a94f66a
|
...does the pragma-comment magic at that place actually work with your PR when both This is actually a situation where the pragma-comment-magic in sokol_app.h is becoming confusing (even though it's very convenient for 'regular situations'). I also just saw that there's this outdated thingie (outdated because UWP / WinRT is no longer supported): Lines 2002 to 2008 in a94f66a
PS: maybe it makes sense to not set any subsystem at all via pragma-comment when both |
CMake + the Visual Studio generator solves this correctly somehow, I did not need any changes to this and the correct subsystem was used..
Maybe removing the force altogether is the better call, but yeah, that makes sense. |
I've checked again, enabling both will open up a console window even when starting through WinMain. Which might be undesired behaviour. So I'm convinced removing these is a better call. |
Yeah, my current thinking is: keep the idea to have both FORCE defines (e.g. what your PR does), but change this block so that no subsystem is set when both are defined:
Can you update the PR for that? Also, while you're at it, can you remove this leftover UWP snippet? Thx :) Lines 2002 to 2008 in a94f66a
|
This should be it. Would you like me to squash it or is this OK? |
Looks good now. I'll play around with it a bit though, will most likely merge on Saturday. |
Ok merged, thanks! I'll also write a little changelog entry. |
My library uses Sokol under the hood and requires you to define
when on Windows by default. If you were to use
add_executable(example main.cpp)
instead, it would not link due to the missing main entrypoint. I could define SOKOL_WIN32_FORCE_MAIN for MyLib to force main(), but then I could not create a WinMain unless I removed it again. I considered doing NO_ENTRY and defining both locally in the library but that seemed like more work (and less in the spirit of open-source) than making a PR.This PR addresses this problem, creating a definition for
SOKOL_WIN32_FORCE_WINMAIN
. This allows you to force either or both, where the default behaviour is the original behaviour.I'm not happy about the length of the extra line I added in the documentation, and I'm open to modify it if you have a better idea.