These days when you create an MFC project, you often encounter two connection errors, such as:
1. LIBCD.lib (crt0.obj): Error lnk2001:unresolved external symbol _main Workaround:
[Project]--[Settings]--Select the "Link" property page,
In Project options, change/subsystem:console to/subsystem:windows.
2. There is also a recurring case of the opposite
LIBCD.lib (wincrt0.obj): Error lnk2001:unresolved external symbol [email protected]
The workaround is: [Project]--[Settings]--Select the "Link" property page to change/subsystem:windows to/subsystem:console in Project options
These two errors can be explained in the following ways:
The first thing to understand is the difference between Win32 application and Win32 Console application . They are all programs that work in a 32-bit Windows environment, and WIN32 application is a common window application that is known as the GUI (graphics user interface graphical subscriber interface. Win32 Console The application (Win32 Console Application) is the Cui (Character user interface character UI), just as the MS-DOS window looks like.
Then why are there connection errors when creating different applications?
The reason is that the entry function for Win32 application is WinMain , and WinMain is the entry function for Windows API form programs.
The entry function for Win32 Console application is main , and main is the standard entry function name for C/s + +.
In other words, if you want to write a traditional C program, you must establish the WIN32 console program, but VC inside the default is Win32 application, then, the above mentioned link errors will often appear.
Question: What does WinMain have to do with the bottom of the main?
WinMain is the entry provided by MFC, and MFC encapsulates its main and submits it to the user in WinMain form. This allows the user to consider several window initialization issues in Windows graphics programming.
The main function is the standard of the C language, any executable C code program must contain the main function entrance, it is actually by the standard C function library to the Ingress address is encapsulated later submitted to the user to use, so that users do not have to consider the general application portal initialization problems (such as setting environment variables, parameter presets , stack fill, etc.), if you do not use MFC, you can directly use the main function plus Windows API to implement the graphical interface window program.
The real program entry is described as __start at the assembly level, which the linker recognizes and formulates as the entrance to the function, and the loader assigns it to the PC to transfer control when it is loaded into the program.
See other people's blog said that the connection also appeared in the following several error LNK2001 errors, by the way, to keep the later search convenient (but I have not met, or make up less ah, hehe ...) )
1.libcmtd.lib (crt0.obj): Error lnk2001:unresolved external symbol _main
For Windows projects to use Windows subsystem instead of console, you can set this: [Project]--[Settings]--Select the "Link" property page,
Change/subsystem:console to/subsystem:windows in Project options
2. Program Entry settings error, hint:
Msvcrtd.lib (crtexew.obj): Error lnk2001:unresolved external symbol [email Protected]
Typically, the program entry function for an MFC project is WinMain, and if you compile the Unicode version of the project, the program entry must be changed to wWinMainCRTStartup, so you need to reset the program entry:
[Project]-- > [Settings]-Select the ' C + + ' property page, select output in category, and then fill in wWinMainCRTStartup in entry-point symbol to
3. 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 wants to use a multi-threaded time library and needs to change the settings: [Project]--[Settings]--Select the ' C + + ' property page, select Code Generation in the category, and then in the usage run-time Select Debug multithreaded or multithreaded in the library,
single-threaded single thread static link library (release version)
multithreaded multithreaded static link library (release version)
Multithreaded DLL multi-threaded dynamic link library (release version)
Debug single-threaded single thread static link library (Debug version)
Debug multithreaded multithreaded static link library (Debug version)
Debug multithreaded DLL multithreaded dynamic link library (Debug version)
Single Thread: Multi-Threading is not required when multi-threaded calls are used in a DOS environment
Multithreading: can run concurrently
Static Library: Link the library and the program directly, you can run away from the MFC library
Dynamic Library: Requires the corresponding DLL dynamic library for the program to run
Release version: used at official release
Debug Version: Debug phase Use
"Turn" Win32 Application and Win32 Console application