Unresolved external symbol _ main solution

Source: Internet
Author: User

Cause: the Win32 application and Win32 console application are mistakenly created during project or project creation.

For details, see the differences between Win32 application and Win32 console application in VC ++.

Http://lihuaxiong-001.blog.163.com/blog/static/2165829920099206263119/edit/

When creating a 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.

Note: The following/Incremental: Yes must also be removed.

3. The program entry settings are incorrect. The prompt is:

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

5. when learning the <in-depth introduction to MFC>, the third chapter of the frame1 program, start to create a Win32 empty console application, and then write the code in the book truthfully, the compilation error is as follows:

My. OBJ: Error lnk2001: unresolved external symbol "class cwinapp * _ cdecl afxgetapp (void )"(? Afxgetapp @ yapavcwinapp @ xz)

The cause is that MFC. cpp is not added to the project.

6. xxxx. OBJ: Error lnk2001: unresolved external symbol _ xx appears in the project XXXX. The reason is that the CPP file of the definition function XX is not added to the project. Add it.

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.