1

I want to remove file names from gcc/g++ compile error messages.

When I run gcc myfolder/temp.c, the result is:

myfolder/temp.c:5:1: error: unknown type name ‘voi’
myfolder/temp.c:87:6: error: conflicting types for ‘max’
myfolder/temp.c:5:5: note: previous declaration of ‘max’ was here

But I want this:

5:1: error: unknown type name ‘voi’
87:6: error: conflicting types for ‘max’
5:5: note: previous declaration of ‘max’ was here

Is there a gcc flag for that?

1 Answer 1

3

I doubt there is an option for this but you could achieve the same result using standard utilities. For instance with cut(1)

 gcc -c myfolder/temp.c 2>&1 | cut -d: -f2-
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Now I want to decrease line numbers by two. I want to change above result to: 3:1: error: unknown type name ‘voi’ 85:6: error: conflicting types for ‘max’ 3:5: note: previous declaration of ‘max’ was here How can I do this?
@MJNaderi that would require several operations: line splitting, arithmetics and concatenation, too much for a standard pipeline filter, but a few lines of perl or awk script would do that. E.g. awk -F: '/^[^:]+:[1-9][0-9]*:/ {printf( "%d", $2 + 2) ; for(i=3;i<= NF;i++) {printf( ":%s", $i) ;} printf ("\n"); }'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.