Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

前端 未结 2 1385
心在旅途
心在旅途 2021-01-27 20:11

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 th

2条回答
  •  盖世英雄少女心
    2021-01-27 20:45

    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.

提交回复
热议问题