Output to a text file the pre-compiler code

Tags: c shell redirect
By : ant2009
Source: Stackoverflow.com

gcc 4.4.2 c89

I have a file called main.c.

I want the result of the pre-comiler and save it to a text file.

I have done the following which creates a text file, but there is nothing in it. It is zero bytes.

gcc -E main.c | > main.txt

Many thanks for any suggestions,

By : ant2009

You don't need to use a pipe operator for redirecting output to a text file. Just use

gcc -E main.c > main.txt

Apart from the obvious error:

gcc -E main.c > main.txt

... you can also use the C preprocessor directly:

cpp main.c > output.c

...which has the added benefit of being independed of the compiler and possible to use in another toolchain.

In both cases in case of problems, take a look at preprocessor command line options.

get rid of the |, or use gcc -E main.c -o main.txt.

This video can help you solving your question :)
By: admin