使用/ p参数(预处理到文件)编译项目(VS 2008)不会编译 [英] Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

查看:454
本文介绍了使用/ p参数(预处理到文件)编译项目(VS 2008)不会编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++项目,我想查看预处理器输出,看看什么#defines和宏将是什么样子。我尝试了 / p 开关打开对编译器的文件选项的预处理(它关闭完全编译,只运行预处理器),但我的项目现在拒绝编译并显示以下列错误的长列表:

I have a project in C++ that I would like to view the preprocessor output to see what some #defines and macros would look like. I tried the /p switch to turn on the preprocess to a file option to the compiler (it turns off full compilation and only runs the preprocessor) but my project now refuses to compile and shows a long list of errors starting with:


无法打开包含文件:'stdafx.h':没有此类文件或目录 。

"Cannot open include file: 'stdafx.h': No such file or directory".

当然,项目编译时没有 / p 参数。任何建议?

The project compiles fine without the /p argument, of course. Any suggestions?

推荐答案

如果您自己运行 cl.exe 那么您将需要提供与IDE在构建时所做的所有相同的参数,否则将无法找到所有包含路径和预处理器宏。但是,还有另一种方法。在项目文件中,选择所需的.cpp文件,然后选择属性> C ++>预处理器>生成预处理器文件。然后编译.cpp文件。

If you run cl.exe on its own then you would need to supply all the same parameters as the IDE does when building, otherwise it can't find all the include paths and preprocessor macros. However, there is another way to do this. In the project file, select the .cpp file you want, and choose Properties > C++ > Preprocessor > Generate preprocessor file. Then compile the .cpp file.

这将生成预处理的文件( file.i 输出目录。这是一个耻辱,没有一个更简单的方法,只是选择一个文件,并打预处理,但这可能很容易做到一个VisualStudio宏。不要忘记以后设置该选项。

This will generate the preprocessed file (file.i I think) in the output directory. It's a shame there isn't an easier way of just selecting a file and hitting 'preprocess' but this could probably be done quite easily with a VisualStudio macro. Don't forget to set the option back afterwards.

这篇关于使用/ p参数(预处理到文件)编译项目(VS 2008)不会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆