Prompt for a solution to the unresolved external symbol _main _c# Tutorial

Source: Internet
Author: User
Prompt appears unresolved external symbol _main searched for the following reasons below
When you create an MFC project, you do not use the MFC AppWizard Wizard, if you do not set the project parameters, you will generate many connection errors at compile time, such as error LNK2001 errors, typical error prompts are:

LIBCMTD.lib (crt0.obj): Error lnk2001:unresolved external symbol _main

LIBCD.lib (wincrt0.obj): Error lnk2001:unresolved external symbol _winmain@16

Msvcrtd.lib (crtexew.obj): Error lnk2001:unresolved external symbol _winmain@16

Nafxcwd.lib (thrdcore.obj): Error lnk2001:unresolved external symbol __beginthreadex

Nafxcwd.lib (thrdcore.obj): Error lnk2001:unresolved external symbol __endthreadex





Here's how to fix this:

1. Windows subsystem Setup error, prompt:

LIBCMTD.lib (crt0.obj): Error lnk2001:unresolved external symbol _main

You can set Windows projects to use the Windows subsystem instead of the console:

[Project]--> [Settings]--> Select the Link property page,

Change/subsystem:console to/subsystem:windows in Project options





2. Console subsystem Setup error, prompt:

LIBCD.lib (wincrt0.obj): Error lnk2001:unresolved external symbol _winmain@16

To use the console subsystem instead of Windows, the console project sets:

[Project]--> [Settings]--> Select the Link property page,

Change/subsystem:windows to/subsystem:console in Project options





3. Program entry settings error, prompt:

Msvcrtd.lib (crtexew.obj): Error lnk2001:unresolved external symbol _winmain@16

Typically, the program entry function for an MFC project is WinMain, and if the Unicode version of the project is compiled, the program entry must be changed to wWinMainCRTStartup, so the program entry needs to be reset:

[Project]--> [Settings]--> Select the Link property page,

Select output in category,

And then fill in the wWinMainCRTStartup in Entry-point symbol, you can





4. Thread Run-time Library Setup error, prompt:

Nafxcwd.lib (thrdcore.obj): Error lnk2001:unresolved external symbol __beginthreadex

Nafxcwd.lib (thrdcore.obj): Error lnk2001:unresolved external symbol __endthreadex

This is because MFC needs to change the settings when it wants to use multiple-threading libraries:

[Project]--> [Settings]--> Select the "C + +" property page,

Select the code Generation in category,

Then select Debug multithreaded or multithreaded in the use Run-time Library

which

single-threaded single-threaded static link library (release version)

multithreaded multithreaded static link library (release version)

Multithreaded DLL multithreaded dynamic link library (release version)

Debug single-threaded single-threaded static link library (Debug version)

Debug multithreaded multithreaded static link library (Debug version)

Debug multithreaded DLL multithreaded dynamic link library (Debug version)

Single-threaded: Multi-Threading is not required, used in DOS environments

Multithreading: can run concurrently

Static Library: Directly link the library with the program, you can run out of the MFC library

Dynamic Library: Requires the corresponding DLL dynamic library, the program can run

Release version: Use when officially released

Debug Version: Debugging phase use

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.