Leonardo Raele
Leonardo Raele

Reputation: 2823

There are some way to print error log to an external file using g++ C++ compiler? (C++)

i'm trying to compile my code with g++ C++ compiler on Windows and the compiler is returning some errors. Ok, as usual. But it's printing so much errors that the console just goes down to the end and I can't see the first lines of error log. My question is: there are any way to print the error log to an external file so I can read the complete error log?

i.e.

g++ *.h *.cpp > error_log.txt

Upvotes: 4

Views: 6868

Answers (3)

Pierre
Pierre

Reputation: 155

g++ *.cpp > log_file.txt 2>&1

First the > allows us to redirect the standard output to the log file. Then by using the 2>&1 we redirect the error output to the standard output. By doing so, we redirect every output to the log_file.txt.

Upvotes: 6

wormsparty
wormsparty

Reputation: 2509

You need to redirect stderr, but it is shell dependant.

For example on sh and bash, you can use:

g++ file 2> error.log

On csh and tcsh it would be:

( g++ file ) >& error.log

Upvotes: 8

vivek
vivek

Reputation: 5229

g++ *.h *.cpp 2> error_log.txt

Notice the '2' It represents stderr.

Upvotes: 4

Related Questions