简体   繁体   中英

How to output preprocessed code AND compile it (Visual Studio)

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

您可以添加自定义生成步骤或新目标以根据定义生成代码后转储预处理程序,转储的预处理程序输出即为已构建的内容。

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.

您可以创建一个进行预处理的自定义生成配置,然后定义一个批处理生成,该批处理生成先生成预处理版本,然后生成实际的编译/链接版本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM