9

I'd like to run the Microsoft Visual Studio Compiler cl.exe without invoking the preprocessor. Is this possible? I thought that simply compiling preprocessed source code (using the /c flag) would make the preprocessor run being a no-op, but apparently that's not the case. I did a bit of benchmarking. Here's a little source file (main.cpp) which just includes some code:

#include <iostream>
#include <string>
#include <windows.h>

Here are some different compiler invocations and their timings:

1: cl /c main.cpp                             ~1.02s
2: cl /EP main.cpp > main-preprocessed.cpp    ~0.5s
3: cl /c main-preprocessed.cpp                ~0.75s

It seems that compiling preprocessed source code is already a bit faster (the preprocessor doesn't need to do anything). However, the difference between 1 and 2 suggests that the actual compiler and assembler just needs a bit more 0.5s. So compiling the preprocessed source code (as done in step 3) is a bit slower than I hoped.

Is there any way to just run the compiler and assembler, without invoking the preprocessor? I'm interested in solutions for MSVC6 up to MSVC10.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
  • Curiousity: why? Are you hoping to speed up compilation somehow? It might be worth trying the same experiment writing a PCH rather than a preprocessed C++ source. – Rup Jan 21 '11 at 10:16
  • 1
    @Rup: I wrote a compiler cache (much like `ccache`) for MSVC, see http://github.com/frerich/clcache - the program uses the preprocessed source code (among other things) to determine whether the compiler/assembler need to be re-run, or whether a previously generated object file can be reused. In the case of a cache miss, I don't want to rerun the preprocessor but just reuse the source code I generated for testing the cache. – Frerich Raabe Jan 21 '11 at 10:47
  • Neat, yes that makes sense. I don't think PCH would help then after all. – Rup Jan 21 '11 at 10:50

2 Answers2

3

To my knowledge there is no way to run the compiler without the preprocessor (regardless of the fact that it doesn't do anything.

However seperating the 2 stages will obviously be slower as you are adding a write to file and then read back of that file. If it doesn't need to do those writes it can hold it in memory and you save a tonne of time waiting for the disk to be written to & read from.

ie Even if you could disable the pre-processor it would still be slower than running both stages simultaneously.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • Yes, of course separating the two stages is slower than doing it in one step. However, in my use case, the second step (compilation & assembling) is possibly omitted. If it's not omitted, I'd like to re-use the previously preprocessed source code instead of running the preprocessor again. – Frerich Raabe Jan 22 '11 at 08:54
0

It may well be that a lot of the time you think the preprocessor is taking is actually time spent writing that large file to disk. The preprocessor should actually take a tiny percentage of the time that the rest of the compiler takes. A big benefit of a normal pre/compilation is that the the compiler can begin compiling while the preprocessor stage is still running, perhaps in a separate thread or as it detects new preprocessor output. The large preprocessor output may not need to ever occupy memory (let alone disk), as it's consumed and overwritten in smaller chunks.

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252