Compilation errors in g++

g++ error message format

Here is a standard error that you might see when you compile something in g++
hackjob.cpp:2:1: unterminated comment

Each section of the error message is separated by a colon.  The first section (hackjob.cpp) is the name of the source file in which the error occurrs.  The second section (2) is the line number on which the error was detected.  The third section (1) is the column number on which the error is detected; it's the only section that isn't present in every error message.  The fourth section (unterminated comment) is a brief message which describes what probably caused the error.  Warnings in g++ follow the same basic format, though a source file with only warnings will still compile into an executable.  Note that when g++ gives you a line number for an error, it doesn't indicate where the error necessary occurred, but where it was detected.  Generally, though, the error is very close to the line number given by g++.
 

Common g++ errors and warnings

Below I've included a listing of common g++ compilation errors and warnings you'll find while compiling C++ programs using g++.  Underneath each entry is an explanation of the meaning behind the error.  Note that the g++ compiler never actually prints out "<something>"; that is just a placeholder for some actual C++ keyword or operator, e.g. int, char, '<<', etc.

unterminated comment
You left out a semicolon at the end of a statement.

parse error before <something>
Probably a missing semicolon or brace before an element, though it could be something else.

syntax error before <something>
You tried to use an operator or keyword that doesn't belong there.  Alternatively, you might have mispelled something (remember that C++ is case sensitive).

stray '\' in program
You're using the forward slash (\) inappropriately, e.g. without enclosing quotes.

missing terminating " character
You left out the terminating double-quotes of a string literal, e.g.

cout << "Hello there;        // Where are the end quotes?

'cout' undeclared (first use this function)
You forgot to put #include <iostream> at the top of your source file.

warning: multi-line string literals are deprecated
You did something like this:

cout << "Hello
         World";

The compiler doesn't like it when you have a carriage return in the middle of a string.  The resulting string probably won't look very good either.

/usr/local/include/g++-v3/bits/stl_algobase.h:793:   instantiated from here
Don't worry about this kind of error, which occurs in library source code that you didn't even write.  These kind of errors will correct themselves when other errors in your program are taken care of.
 

A final piece of advice

Unfortunately, this was not a comprehensive list of errors for g++.  You will likely find many more over as you use g++ in future courses.  Remember that the error messages are never meaningless, so don't be afraid to read them closely to try to figure out what they are saying.  If all else fails, you can try compiling under Visual C++, which not only provides more well-written error messages, but also comprehensive online documentation of all error and warning messages.