How do I capture all of my compiler's output to a file?
Solution 1
The compiler warnings happen on stderr
, not stdout
, which is why you don't see them when you just redirect make
somewhere else. Instead, try this if you're using Bash:
$ make &> results.txt
The &
means "redirect stdout and stderr to this location". Other shells often have similar constructs.
Solution 2
In a bourne shell:
make > my.log 2>&1
I.e. > redirects stdout, 2>&1 redirects stderr to the same place as stdout
Solution 3
Lots of good answers so far. Here's a frill:
$ make 2>&1 | tee filetokeepitin.txt
will let you watch the output scroll past.
Solution 4
Assume you want to hilight warning and error from build ouput:
make |& grep -E "warning|error"
Solution 5
The output went to stderr. Use 2>
to capture that.
$make 2> file
pecker
Updated on July 08, 2022Comments
-
pecker almost 2 years
I'm building an opensource project from source (CPP) in Linux. This is the order:
$CFLAGS="-g Wall" CXXFLAGS="-g Wall" ../trunk/configure --prefix=/somepath/ --host=i386-pc --target=i386-pc $make
While compiling I'm getting lot of compiler warnings. I want to start fixing them. My question is how to capture all the compiler output in a file?
$make > file
is not doing the job. It's just saving the compiler command likeg++ -someoptions /asdf/xyz.cpp
I want the output of these command executions. -
ephemient about 14 yearsI think that the return code of a pipeline is usually the return code of the last command; in this case,
tee
notmake
. So the|| more
unfortunately doesn't do what you say it does. Comparefalse || echo $?
tofalse | cat || echo $?
. -
ephemient about 14 yearsThis is equivalent to
make > results.txt 2>&1
but with less typing :) -
Dana the Sane about 14 yearsIs there an equivalent for pipes?
-
dmckee --- ex-moderator kitten about 14 years@ephemient: Ah. You are right....heck, I made that work once, and now I can't recall how. In anycase, I use
tee
in this application fairly often. -
ephemient about 14 years@Dana the Sane: Bash 4 has
|&
for pipes, which is equivalent to2>&1 |
. -
ephemient about 14 years
shopt -s pipefail
, perhaps? -
CosmicGiant almost 8 yearsWhile code-only answers are not forbidden, please understand that this is a Q&A community, rather than a crowd-sourcing one, and that, usually, if the OP understood the code being posted as an answer, he/she would have come up with a similar solution on his/her own, and wouldn't have posted a question in the first place. As such, please provide context to your answer and/or code by explaining how and/or why it works.
-
Piyush Soni about 7 yearsPlease note that >&, &> and 2>&1 are all shell dependent, and may work or not depending on if you have bash/csh or other shells. @Alberto: I was confused too, because I was using csh and &> didn't work for me while >& worked. This was the reason.
-
FractalSpace about 6 yearsThis does not answer 'How do I capture all of my compiler's output to a file? '
-
2785528 almost 6 yearsWhen you compile within emacs, all the compiler output is captured in the * compilation * buffer of the editor. Saving this buffer to a file is then, in the emacs style, a single command, C-x Cw (and choose a file name).
-
Steven Lee over 2 years@PiyushSoni: I was using csh and
&>
didn't work while>&
worked.