Compiling a project (VS 2008) with the /p argument

2019-03-06 14:49发布

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:

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

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

2条回答
你好瞎i
2楼-- · 2019-03-06 15:21

Are all the other options (like /I) still the same when you compile with /p? It sounds like it's not picking up your header files. Alternately because it's trying to pre-process all the includes it's no longer generating the stdafx.h precompiled header - you could try just including all the needed headers directly instead of that.

查看更多
够拽才男人
3楼-- · 2019-03-06 15:24

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.

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.

查看更多
登录 后发表回答