This article mainly introduces some common link error solutions in VC6.0 development. For more information, see
(1) error LNK2001: unresolved external symbol _ main
No.: LNK2001
Unresolved external symbol: _ main.
Error analysis: the main function is missing. Check whether the spelling or case of main is correct.
(2) error LNK2005: _ main already defined in xxxx. obj
No.: LNK2005
_ Main already exists in xxxx. obj.
Error analysis:
The reason for direct connection is that the program has multiple (more than one) main functions. This is a common mistake made by Junior C ++ students during their initial programming. This error usually does not contain two main functions in the same file, but contains multiple cpp files in a project, each cpp file has a main function. The process of triggering this error is generally as follows: You have written the debugging of a C ++ program, and then you are preparing to write the second C ++ file, therefore, you may close the current cpp file word window through the close button in the upper right corner (or not close, this operation does not affect the final result ), then, a new cpp file is created through the menu or toolbar. In this new window, the program is compiled, compiled, and the above error occurs. The reason is: When you create the second cpp file, the original project is not closed, so you do not intend to add the new cpp file to the project where your previous program is located. Switch to the "File View" View, expand the "Source Files" node, and you will find two Files.
When writing C ++ programs, you must understand what is Workspace and Project. Every program is a Project. A Project can be compiled into an application (*. exe) or a dynamic link library (*. dll ). Generally, each Project can contain multiple. cpp files,. H files, and other resource files. Only one main function can exist in these files. When a beginner writes a simple program, there is usually only one cpp file in a Project. A Workspace is a collection of projects. When debugging complex programs, a Workspace may contain multiple projects. However, for simple programs for beginners, a Workspace usually contains only one Project.
After a program is completed and another program is written, you must select the "Close Workspace" item in the "File" menu and Close the previous project to proceed to the next project. One way to avoid this error is to completely disable VC6 every time you write a C ++ program, rewrite and open VC6, and write the next program.