views:

362

answers:

6

Hello,

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 to a file?

$make > file is not doing the job. Its just saving the the compiler command like g++ -someoptions /asdf/xyz.cpp I want the output of these command executions.

A: 

Try make 2> file. Compiler warnings come out on the standard error stream, not the standard output stream. If my suggestion doesn't work, check your shell manual for how to divert standard error.

David Thornley
+6  A: 

In a bourne shell:

make > my.log 2>&1

I.e. > redirects stdout, 2>&1 redirects stderr to the same place as stdout

Nathan Kidd
+1  A: 

The output went to stderr. Use 2> to capture that.

$make 2> file
KennyTM
+6  A: 

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:

$make &> results.txt

The & means "redirect stdout and stderr to this location".

John Feminella
ephemient
Is there an equivalent for pipes?
Dana the Sane
ephemient
Dana the Sane
+3  A: 

Lots of good answers so far. Here's a frill:

$ make 2>&1 | tee filetokeepitin.txt 

will let you watch the output scroll past.

dmckee
I think that the return code of a pipeline is usually the return code of the last command; in this case, `tee` not `make`. So the `|| more` unfortunately doesn't do what you say it does. Compare `false || echo $?` to `false | cat || echo $?`.
ephemient
@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.
dmckee
`shopt -s pipefail`, perhaps?
ephemient
+1  A: 

From http://www.oreillynet.com/linux/cmd/cmd.csp?path=g/gcc

The > character does not redirect the standard error. It's useful when you want to save legitimate output without mucking up a file with error messages. But what if the error messages are what you want to save? This is quite common during troubleshooting. The solution is to use a greater-than sign followed by an ampersand. (This construct works in almost every modern UNIX shell.) It redirects both the standard output and the standard error. For instance:

$ gcc invinitjig.c >& error-msg

Have a look there, if this helps: another forum

Gauthier
ephemient