We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3320 - SDL_windows_main.c defines both console application entry points
Summary: SDL_windows_main.c defines both console application entry points
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: main (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-05 13:00 UTC by Simon Hug
Modified: 2016-10-14 15:28 UTC (History)
1 user (show)

See Also:


Attachments
Only define wmain if UNICODE is set. (438 bytes, patch)
2016-05-05 13:00 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hug 2016-05-05 13:00:22 UTC
Created attachment 2443 [details]
Only define wmain if UNICODE is set.

The SDLmain file src/main/windows/SDL_windows_main.c defines both entry points for console applications, main and wmain. This seems to confuse MSVC. It outputs a LNK4067 warning and then chooses main, which is a shame because only wmain has the unicode handling. Using SDLmain.lib provided on libsdl.org, the linker also goes for main.

I'm proposing to not define the main entry point at all. wmain should be supported well enough with MSVC.
Comment 1 Sam Lantinga 2016-10-01 19:31:51 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/92dc590a7116
Comment 2 Sam Lantinga 2016-10-13 02:51:11 UTC
With that change only the wmain() entry point is defined, and applications that link with main() no longer build.
Comment 3 Sam Lantinga 2016-10-13 02:52:17 UTC
Simon, I can't reproduce the linker issue you're seeing here. I am however able to reproduce not being able to build with your change by creating a new console application in Visual Studio and linking it to SDL.

Can you investigate?
Comment 4 Simon Hug 2016-10-13 15:50:25 UTC
Oops, my testing was incomplete. I probably linked with the coff object file of SDL_windows_main.c directly instead of packaging it first into a library file. I really thought I tested both.

It looks like the MSVC linker ignores the wmain symbol in the lib file when searching for possible entry points. It works if the symbol is in an obj file, but here it just falls back to main.

I didn't find a way to get the linker to select it without forcing the entry point manually. How annoying.

If unicode arguments are necessary, console_ansi_main could always go the GetCommandLine route like WinMain.
Comment 5 Sam Lantinga 2016-10-13 16:49:05 UTC
That sounds like a good approach. Want to test and submit a patch for that?
Comment 6 Simon Hug 2016-10-14 10:02:56 UTC
I have opened a new bug 3452 for that since the issue is a bit different.

I guess you can mark this bug as invalid or wontfix.
Comment 7 Sam Lantinga 2016-10-14 15:28:29 UTC
Closing, thanks!