Reputation: 2311
I understand that Visual C++ Linker chooses mainCRTStartup
/wmainCRTStartup
when option /SUBSYSTEM
is set to CONSOLE
.
What I do not understand is how the linker chooses between the two.
I tested with a simple program on VC 2015. If wmain exists (even main also exists), wmain is called. Otherwise main is called.
Upvotes: 1
Views: 1673
Reputation: 91
The linker will attempt to infer which entry point routine is needed by walking the symbol table of your objs. It searches for _wmain before _main, which is why the former was selected even though you have both. The linker then pulls the appropriate startup routine from your default libc static library.
You can override much of this by supplying the /ENTRY, /DEFAULTLIB, and /NODEFAULTLIB options to your linker. But normally, you let the linker handle this automatically.
Also, you should only have one main C function in your program. Either explicitly define one or the other, or go the TCHAR route and let your compiler replace _tmain() with either the main() or wmain() depending on if UNICODE is defined.
Upvotes: 3