I\'d like to be able to view preprocessor output in order to make sure my preprocessor directives run correctly. Dev-C++ has an option in Tools > Compiler Options... > General t
I've added the command -E C:\Personal\preprocessed.cpp. I got a compiler error saying the file didn't exist, but shouldn't the compiler just create the file in that case?
No, because the -E option takes no argument, filename or otherwise. It simply instructs the compiler to do nothing but preprocessing. The preprocessed code is written to the standard output. Thus:
Thus:
g++ -E C:\Personal\preprocessed.cpp foo.cpp
tells the compiler that you want run g++ -E
with the pair of input files C:\Personal\preprocessed.cpp
and foo.cpp
,
which as you've discovered is not allowed.
The simple thing that you want to do is absurdly difficult with your IDE of choice. Assuming
the source file you want to preprocess is C:\Personal\foo.cpp
and the g++
is in your PATH
,
just open a command window in C:\Personal
and run:
g++ -E foo.cpp > foo.ii
I suggest the output file foo.ii
- though you can call it whatever you like - because g++
recognizes the extension .ii
as denoting C++ source code that has already been preprocessed. You can run:
g++ -Wall -o prog foo.ii
and foo.ii
will be compiled and linked as program prog
without being preprocessed again.