The system prompts a solution for unresolved external symbol _ main.

Source: Internet
Author: User

The following error occurs when unresolved external symbol _ main is searched:
When creating an MFC project, the MFC Appwizard wizard is not used. If the project parameters are not set, many connection errors will be generated during compilation, such as error lnk2001. Typical error prompts include:

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

The solution is as follows:

1. Windows subsystem setup error, prompt:

Libcmtd. Lib (crt0.obj): Error lnk2001: unresolved external symbol _ main

For Windows projects, you must use the Windows subsystem instead of the console. You can set it as follows:

[Project] --> [settings] --> select the "Link" property page,

Change/subsystem: console to/subsystem: Windows in project options.

2. the console subsystem settings are incorrect. The following message is displayed:

Libcd. Lib (wincrt0.obj): Error lnk2001: unresolved external symbol _ winmain @ 16

For a console project, use the console subsystem instead of windows. Set:

[Project] --> [settings] --> select the "Link" property page,

Change/subsystem: Windows to/subsystem: console in project options.

3.ProgramPortal setting error, prompt:

Msvcrtd. Lib (crtexew. OBJ): Error lnk2001: unresolved external symbol _ winmain @ 16

Generally, the program entry function of the MFC project is winmain. If the Unicode version of the project is compiled, the program entry must be changed to wwinmaincrtstartup. Therefore, you need to reset the program entry:

[Project] --> [settings] --> select the "Link" property page,

In category, select output,

Enter wwinmaincrtstartup in entry-point symbol.

4. When the thread is running, the database settings are incorrect. The prompt is:

Nafxcwd. Lib (thrdcore. OBJ): Error lnk2001: unresolved external symbol _ beginthreadex

Nafxcwd. Lib (thrdcore. OBJ): Error lnk2001: unresolved external symbol _ endthreadex

This is because when MFC uses a multi-threaded library, you need to change the settings:

[Project] --> [settings] --> select the "C/C ++" attribute page,

In category, select code generation,

Select debug multithreaded or multithreaded in the use run-time library.

Where,

Single-threaded single-thread static link library (Release Version)

Multithreaded multi-thread static link library (Release Version)

Multithreaded DLL multi-thread dynamic link library (Release Version)

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

Debug multithreaded multi-thread static link library (debug version)

Debug multithreaded DLL multi-thread dynamic link library (debug version)

Single thread: When multi-thread calling is not required, it is usually used in DOS environments.

Multithreading: Concurrent Operation

Static Library: link the library directly with the program and run it without the MFC library.

Dynamic library: The corresponding DLL dynamic library is required for the program to run.

Release Version: used for official release

Debug version: used during debugging

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.