error C2143: syntax error: missing ';'( in front of '}'. error LNK1120: 1 unresolved external command. error LNK2019: unresolved external symbol _main, which is in function

In the past, compilers such as codeblocks and DEVC++ were basically used for introductory learning. I don’t think there is much hindrance. But recently, when I use VC 2010 or VS, when I execute it under pure C language compilation, there will always be question marks on my face like this or that? ?? errors, warnings.

Even if it is such a program temp1.c that a primary school student can understand, it will not be passed! ! ! .

#include <stdio.h>        //temp1.c
int main()
{
    
    
   printf("Hello, World!");
   return 0;
}

Such a program, 5 mistakes! I admit that I haven't typed for a long time, but it is not possible to not even add the ';' semicolon, right? Take a closer look, yes, there is indeed no grammatical error. Is there something wrong with the compiler? ? ?
insert image description here
But it was later discovered that when multiple projects are opened in the current window, the VC compiler will compile these projects one by one by default. That is to say, there is no problem with the simple and terrible temp1 above, but Something went wrong with other C files for the current window.

As shown in the picture, I have created 3 projects temp1, temp2, temp3, corresponding to 3 C language .c files respectively. Window 1----temp1.c is indeed ok, so why did 2 kinds of errors appear twice when compiling?
insert image description here

That's right, I only compile the temp1 project, but VC compiles temp1~temp3 one by one, that is to say, these two kinds of errors are due to the fact that the temp2.c and temp3.c windows are empty, so two kinds of errors appear Appears twice, ie 4 errors (2 types of errors).

Looking down, I paste the program into the temp2.c window and compile it again:
insert image description here
at this time, although I still compiled temp1.c, it is obvious that the other two have also been compiled. But these two errors are caused by the fact that temp3.c is empty. Then if I paste the third one into the program, you should be able to guess the result --- 0 erros is
insert image description here
absolutely correct!

In the same way, suppose I owe a hand, and a semicolon is missing in temp2.c; the purpose is to make errors in other project c files currently opened, and an error will also be reported when compiling temp1.c at this time.
insert image description here
But what we need to know is that this is caused by errors in other project files, not because temp1. That's right!

Because the error is caused by other projects, running temp1 directly regardless of the error can get the correct result.
insert image description here

To sum up, when encountering these types of errors, especially when writing dozens or hundreds of lines of programs, first eliminate the most basic non-subjective problems, and then go to the program to find bugs, which may save you from suffering .

error LNK1120: 1 unresolved external command
error C2143: syntax error: missing ';' (before '}'
error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

I wrote it in a hurry, if there is any inappropriate understanding, please correct me and make progress together!

Guess you like

Origin blog.csdn.net/AII_IIA/article/details/113624172