How to output preprocessed code AND compile it (Vi

2020-06-16 04:48发布

问题:

I'm generating preprocessor output (.i) from Visual Studio, but also want to do the actual build. Is there a combination of flags that will both output the .i file without then stopping the compiler from going ahead with the build as normal?

This is currently just C++ but will probably want to use this with CUDA later, so prefer answers that work within Visual Studio rather than require command line (unless it works for CUDA too).

The point of this is to save the time it takes to do Project->Properties->Config Props->C/C++->Preprocessor->Generate Preprocessed File Yes/No plus Rebuild. Particularly it is irksome to me that the preprocessor has to run twice, so a solution that somehow generates the .i file in part 1 and then compiles that file in part 2 would be fine.

The exact version of Visual Studio I'm using is VS 2008 Express

回答1:

You can add a custom build step or a new target to dump the preprocess after the code is built by definition the dumped preprocessor output is what is built.



回答2:

You can create a custom build config that does pre-processing and then define a batch build that builds the pre-processed version followed by the actual compiled / linked version.



回答3:

Use the switch /P Example- cl /C sample.c

The above will generate a .I file with same name (sample.I). Now to compile the .I file, just rename .I file to .C then do cl /c to compile and generate an object file.