How to redirect or echo gcc messages to file?

Submitted by jdarren
on October 26, 2005 - 2:09pm

I know this is a terribly newbie question, but...how do I redirect or echo gcc warning and error messages to a file?

Thanks!

-jdarren

jdarren Why dont you try

Anonymous (not verified)
on
October 26, 2005 - 4:03pm

jdarren

Why dont you try:

gcc foo.c >> bar.txt

That should re-direct the standart output from the opperation to the file. It will not re-direct the standard error output, i'm not sure that a gcc warning wouldn't be directed to std err, so you had better give it a try and see.

DJ.

Useful guide: http://www.tldp

Ano Nymous
on
October 26, 2005 - 4:33pm

Useful guide: http://www.tldp.org/LDP/abs/html/ with all kind of goodies. You're asking about I/O redirection.

gcc &> file to redirec both stderr and stdout, warnings and erors are printed to stderr by gcc. If you want to redirect only stderr then use gcc 2> file. Use the tee program to both print and log data.

E.g. the following command will swap stdout and stderr, print out all messages on screen and also log all warning and errors to "file".

gcc 1>&2 2>&1 | tee file

This is all fine and well but

Anonymous (not verified)
on
May 3, 2006 - 7:14am

This is all fine and well but when you place the command in a make file such as

$(OBJDIR)\SomeObjFile.o : $(SRCDIR)\$(@B).c $(INCLUDES)
$(CC) $(CFLAGS) -c -o$(OBJDIR)\$(@B).o \
$(@B).cpp 1>&2 2>&1 | tee $(@B).err

the 1>&2 2>&1 | tee $(@B).err are completely ignored.
Anybody know why?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.