5

I wished to know if someone knew how to put the compilation warnings of GCC in a text file ?

For example :

I wrote (willingly) a undefined function foo(). So gcc tell me :

warning: implicit declaration of function 'foo [Wimplicit-function-declaration]

How can i get this line written in a text file ? I search for an option in the man page of gcc :

https://linux.die.net/man/1/gcc

but didn't find anything about that. I tried the commands echo and tee to do that but those commands only catch the compilation line (eg : ... gcc -o test test.o main.o ...)

1 Answers1

8

You can redirect the output, say your program is:

main()
{
}

When you compile, gcc will say something like:

a.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
 main()
 ^~~~

That is shown in the terminal. What you want to do is redirect this to a file. In this case, you need to redirect the standar error output (in the terminal you see both: standard ouput, and standard error output):

$ cc a.c 2> output.txt

2> means send the error output (in this case warnings) to this file.

a simple > would redirect the standard output.