Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save the error output of gcc to file

Tags:

c++

gcc

When I compile my code I get a bunch of errors which I span through the screen and I can see where does the error start. How can I save the output of gcc to a file?

I tried tricks like

gcc > log.txt

or grepping the result but it didn't work. Searching google yields mostly result on explaining how to print to file with c++

like image 318
Yotam Avatar asked Aug 02 '11 15:08

Yotam


1 Answers

GCC outputs errors to the standard error stream not to the standard output stream. You need to redirect standard error, instead of standard output. In bash:

gcc 2> log.txt
like image 100
R. Martinho Fernandes Avatar answered Sep 18 '22 10:09

R. Martinho Fernandes