问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/4757231/how-can-i-run-the-msvc-preprocessor-and-compiler-in-two-separate-steps