views:

145

answers:

3

When gcc prints out a warning or error, it shows the full path of the file that contains the error. Is there a flag to shorten the output to just the filename?

+5  A: 

It just depends on how you invoke gcc:

/tmp/c$ gcc -Wall bad.c
bad.c:1: warning: return type defaults to ‘int’
bad.c: In function ‘main’:
bad.c:1: warning: control reaches end of non-void function

vs

/tmp/c$ gcc -Wall /tmp/c/bad.c
/tmp/c/bad.c:1: warning: return type defaults to ‘int’
/tmp/c/bad.c: In function ‘main’:
/tmp/c/bad.c:1: warning: control reaches end of non-void function

vs

/tmp/c$ gcc -Wall ../../tmp/c/bad.c
../../tmp/c/bad.c:1: warning: return type defaults to ‘int’
../../tmp/c/bad.c: In function ‘main’:
../../tmp/c/bad.c:1: warning: control reaches end of non-void function

where contents of bad.c are just

main() { }

if anyone cares.

Mark Rushakoff
True, that works, but what about if there's already a complicated build system set up? It'd be nice if I could just add something to CFLAGS to clear up the output.
nicholasbishop
+1  A: 

Sometimes I use a sed script for that (f.e. when using cmake, which always uses full pathes). This can be useful also to sanitize other parts of log, f.e. template names in C++.

liori
A: 

gcc 2> /dev/null :-) On a real OS.

xcramps