tags:

views:

57

answers:

4

Hello,

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,

+1  A: 

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

Alok
+1  A: 

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

gcc -E main.c > main.txt
goldPseudo
Found the answer in this post http://stackoverflow.com/questions/2133009/how-can-i-compile-c-code-that-has-already-been-c-pre-processed-with-gcc. However, I did try that and it didn't work for me. I was getting some errors saying that it couldn't find some header files. However ,that is the correct way to do that. Thanks.
robUK
@robUK: what? .
Alok
+1  A: 

You might want to look into the ‘cpp‘ program, which is the C preprocessor that gcc uses.

cpp in.c > out.c
Charlie Somerville
+2  A: 

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.

Kornel Kisielewicz