CP107 Common Compiler Error Explanations

These are some common compiler errors and their explanations as to why they might have happened. This is a living document and I am sure there are instances that you will run across where the possible cause is not the reason why you are getting an error. If so, please show it to me.

fatal error C1004: unexpected end of file found - Possible Causes: uneven number of braces in code.

error C2065: 'variable name' : undeclared identifier - Possible Causes: used a variable that hasn't been declared yet

warning C4390: ';' : empty controlled statement found; is this the intent?

Possible Causes -

if( statement ) ; // note this semi colon here...ooops!

{

     other code here ;

}

error C2143: syntax error : missing ';' before 'if' Possible Causes – did you forget to put a ; at the end of the statement immediately above it?

error C2146: syntax error : missing ';' before identifier 'variable or function name' Possible Causes - need a semi colon to end a statement above where the IDE shows the error.

error LNK2001: unresolved external symbol _WinMain@16

Debug/test2.exe : fatal error LNK1120: 1 unresolved externals

Possible Causes - you have selected the wrong type of project when you had you the wizard generate your workspace. You must select the Win32 Console Application; you probably selected the Win32 Application.

error C4716: 'function name' : must return a value

Possible Causes - the function must return a value since your prototype states that it will return a value. So if you define the function as int Foo () ;

your function must return an integer.

fatal error C1010: unexpected end of file while looking for precompiled header directive

Possible Causes - the project is set to use precompiled headers and will not compile without them. You have two choices:

1. go into the project and remove the option of using precompiled headers

2. put at the very top of the code (has to be the first line of code the

compiler sees)

#include "stdafx.h"

warning C4101: 'variable name' : unreferenced local variable

Possible Causes - you declared a variable and then never used it

error C2447: missing function header (old-style formal list?)

Possible Causes - you have two sets of braces which do not contain each other

Here is an example of code which will produce this result.
int main(int argc, char* argv[])
{
cout << "Hello World!\n" << flush ;
return 0;
}

{
cout << "run while you can" << flush ;
}

Notice that the second set of braces is below the main function and is not part of a function. The compiler doesn't know what you are trying to do with the code you have written here.

warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
error C2146: syntax error : missing ';' before identifier 'i'
fatal error C1004: unexpected end of file found

Possible Causes - you have two sets of braces which do not contain each other

Here is an example of code which will produce this result.

int main ( )
int i ;
{
return 0;
}

The declaration for the variable i must be either above the statement 'int main()' or below the opening brace for this to be syntactically correct C++.

error C2239: unexpected token '{' following declaration of 'main'

Possible Causes - the following code will cause this error. Note that above main could be replaced by any function that you forget to put parens after (with or without parameters).

#include

int main // PROBLEM IS HERE! no parens so C++ doesn't know you mean this to be a function
{
cout << "Hello world!" << flush ;
return 0;
}