Reputation: 1851
Is it possible to generate preprocessor output and compilation in one step with GCC?
Something like:
gcc -E -c main.cc -o main.o
that would generate main.o and main.i
Upvotes: 17
Views: 14779
Reputation: 882686
No, not with -E
itself, the -s
, -c
and -E
options are called "stop" options. They actually halt the process at a specific point so you can't keep going.
If you want to do that, you have to do it in two passes, or use -save-temps
to keep copies of the temporary files normally deleted during compilation.
From the gcc
manpage, stuff discussing -E
(slightly paraphrased):
If you only want some of the stages of compilation, you can use -x (or filename suffixes) to tell gcc where to start, and one of the options -c, -S, or -E to say where gcc is to stop. Note that some combinations (for example, -x cpp-output -E) instruct gcc to do nothing at all.
-E means: stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output (or to the output file if -o is specified).
If you use the -E option, nothing is done except preprocessing.
And a description of -save-temps
:
-save-temps
Store the usual "temporary" intermediate files permanently; place them in the current directory and name them based on the source file.
Thus, compiling foo.c with -c -save-temps would produce files foo.i and foo.s, as well as foo.o.
This creates a preprocessed foo.i output file even though the compiler now normally uses an integrated preprocessor.
Upvotes: 8
Reputation: 145919
Yes.
Look at gcc
-save-temps
option.
It compiles the source file and saves the result of the preprocessing in a .i
file. (It also saves the result of the assembler phase to a .s
file).
gcc -save-temps -c main.cc -o main.o
will generate main.o
but also main.i
and main.s
.
main.i
is the result of the preprocessing.
Upvotes: 26