Compile a SectionProgramWhen a connector error occurs:
Error lnk2019: unresolved external symbol _ main referenced in function ___ tmaincrtstartup
The program is roughly as follows:
Visual Studio 10.0
Properies | General | Character Set: "use Unicode Character Set"
Properies | linker | System: "Console (subsystem: Console )"
Namespace mystock {const int .....; const wchar_t * const .....; class ....... {}; class ....... {}; ......int _ cdecl wmain (INT argc, wchar_t * argv []) {.......... ...... ;}} // namespace mystock
Why? Does my main function look right?
I believe the reader is very clear about what kind of main function the CRT will require under. But this issue has never been encountered.
After 20 minutes, I finally remembered it. Or, if you are right, you still have no idea.
I noticed that the connector wanted "_ main". Why is there "_"? Even the _ tmain generated by the wizard, is it main or wmain after macro expansion?
Does the C compiler automatically underline cdecl? By the way, is it because I put wmain in a namespace?
Just bite your teeth and give it a try:
Extern "C" int _ cdecl wmain (INT argc, wchar_t * argv []) {......
The connector error disappears.
If you encounter similar problems, I hope this articleArticleIt is helpful.
If you know more details, please reply to the instructions:
1. Why is extern "C" required for the main function to be put into namespace?
2. Main is not stored in namespace, but in the. cpp file, is extern "C" the default setting of the compiler? No.