PDA

View Full Version : How to get number line of error from GCC ?



engineerball
August 26th, 2007, 04:07 PM
How i can get number line of error from GCC ?
If I compile my program and have more errors. How can i got its.
Ex.
after I compile source code and it have errors.


read_str.cpp:5: error: ‘string’ was not declared in this scope
read_str.cpp:6: error: variable or field ‘Convert2D’ declared void
read_str.cpp:6: error: ‘string’ was not declared in this scope
read_str.cpp:7: error: ‘string’ has not been declared
read_str.cpp: In function ‘int main(int, char**)’:
read_str.cpp:25: error: ‘CountLine’ cannot be used as a function
read_str.cpp:26: error: ‘cout’ was not declared in this scope
read_str.cpp:26: error: ‘endl’ was not declared in this scope
read_str.cpp:29: error: cannot convert ‘std::string’ to ‘int’ for argument ‘2’ to ‘void FindLastLine(int*, int)’
read_str.cpp:36: warning: comparison between signed and unsigned integer expressions

I want 6, 7, 25, 26, 29, 36.

Can it get number from GCC direct ?

Sorry I'm very poor in English.
Thank you.

CptPicard
August 26th, 2007, 06:13 PM
Sorry, but I don't understand your question... aren't you already getting the line numbers of compilation errors from gcc's output as demonstrated?

Lux Perpetua
August 26th, 2007, 08:31 PM
Do I understand correctly that you want a program to parse the GCC error output and simply display the line numbers?

This may get you started:
g++ yourfile.cpp 2>&1 1>/dev/null | sed --quiet 's/\(.*:\)\([0-9]*\)\(:.*\)/\2/p'More on sed: http://www.grymoire.com/Unix/Sed.html