g++ error message formatHere 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 warningsBelow 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 missing terminating " character cout << "Hello there; // Where are the end quotes? 'cout' undeclared (first use this function) warning: multi-line string literals are deprecated 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. |
A final piece of adviceUnfortunately, 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. |