简体   繁体   English

如何输出预处理的代码并进行编译(Visual Studio)

[英]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. 我正在从Visual Studio生成预处理器输出(.i),但也想进行实际的构建。 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? 是否有既可以输出.i文件又不会停止编译器正常进行编译的标志组合?

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). 当前仅是C ++,但以后可能希望将其与CUDA一起使用,因此更喜欢在Visual Studio中运行的答案,而不是要求命令行(除非它也适用于CUDA)。

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. 这样做的目的是为了节省执行Project-> Properties-> Config Props-> C / C ++-> Preprocessor-> Generate Preprocessed File是/否以及重建的时间。 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. 特别令我讨厌的是预处理器必须运行两次,因此以某种方式在第1部分中生成.i文件,然后在第2部分中编译该文件的解决方案会很好。

The exact version of Visual Studio I'm using is VS 2008 Express 我正在使用的Visual Studio的确切版本是VS 2008 Express

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

Use the switch /P Example- cl /C sample.c 使用开关/ P Example- cl / C sample.c

The above will generate a .I file with same name (sample.I). 上面的代码将生成一个同名的.I文件(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. 现在要编译.I文件,只需将.I文件重命名为.C,然后执行cl / c即可编译并生成目标文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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