Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect the output of gcc compiler to a file?

Tags:

gcc

Redirection operator does not work. So how should we do it? One more question, in makefile, how can we give arguments from command line, like

run: a.out
    ./a.out **<input>**
like image 747
avd Avatar asked Sep 29 '09 05:09

avd


People also ask

Can I use GCC to compile C code?

Gcc supports various programming languages, including C, is completely free and is the go-to compiler for most Unix-like operating systems. In order to use it, we should make sur we install it on our computer, if it's not already there.

What is GCC option?

When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker.


2 Answers

gcc prints its error messages to stderr, so you have to redirect stderr:

gcc -o foo foo.c 2> foo.gccmessages

You give arguments on the command line always in the same way

./a.out argument1 argument2 argument3
like image 180
Martin v. Löwis Avatar answered Sep 17 '22 15:09

Martin v. Löwis


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.

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

like image 26
rpappalax Avatar answered Sep 19 '22 15:09

rpappalax