I know this is a terribly newbie question, but...how do I redirect or echo gcc warning and error messages to a file?
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.
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 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?