cl.exe (Visual Studio C/C++ language compiler) compiles source file to preprocessed file with the /P flag e.g. cl /P Source.c
creates Source.i
I want to compile this Source.i (not the Source.c) into Source.obj. How should I do it? Can't find a flag that takes preprocessed file as an input.
You don't need to do anything special. It's a valid C++ source file that just goes to your compiler. (Though it won't be a portable source file, since all the toolchain's own standard library gubbins, and whatever else, have been expanded.)
The only trick here is that usually the "intermediate" step is done for you by the front-end, taking the preprocessed source and passing it to the "real" compiler. But you can still just do that yourself.
However, you may want to rename it so it has a nice C++-like extension. Otherwise, you can pass /Tp
to force your file to be treated as C++, regardless of extension. (For GCC this would be -x c++
.)
The other thing to note is that it's then still going to run a preprocessing step on your file, not knowing that it's no longer needed (all the preproc directives have already been expanded by your first step), so that's a little wasted additional time. But then this is not (or should not be) a typical workflow.
cl /P Source.c
cl /Tp Source.i