Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I capture all of my compiler's output to a file?

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 like g++ -someoptions /asdf/xyz.cpp I want the output of these command executions.

like image 263
pecker Avatar asked Feb 19 '10 15:02

pecker


People also ask

How do I redirect output to a file?

Method 1: Single File Output Redirection“>>” operator is used for utilizing the command's output to a file, including the output to the file's current contents. “>” operator is used to redirect the command's output to a single file and replace the file's current content.

How do I redirect output to a file in GCC?

Try: $ make 2>&1 | tee your_build_log. txt this will redirect stdout, 2>&1 redirects stderr to the same place as stdout while allowing you to simultaneously see the output in your terminal.


2 Answers

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.

like image 192
John Feminella Avatar answered Sep 20 '22 08:09

John Feminella


In a bourne shell:

make > my.log 2>&1

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

like image 34
Nathan Kidd Avatar answered Sep 22 '22 08:09

Nathan Kidd