Error lnk2019: unresolved external symbol _ main referenced in function ___ tmaincrtstartup

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.