Preprocessor output on Qt Creator

谁都会走 提交于 2019-12-04 00:31:50

问题


I am compiling C code in Qt Creator and I need to look at the preprocessor output.

I added the -E flag to the make, but I don't see the *.i files:

mingw32-make.exe -e -w in \qt\qt-build-desktop

Please help.


回答1:


-E is a gcc option, not a make option, so passing it to make won't do anything. Also, using -E works fine for a single file, but will break your build as no proper .o file is generated (it contains the preprocessed source). What works fine though is adding the following to the .pro file:

QMAKE_CXXFLAGS += -save-temps

Now if you build your project, the preprocessed source of source file foo.cpp is kept as foo.ii. (tested with make+gcc on OS X, I'd assume it works for mingw, too).

Edit: Just learned that the equivalent flag for MSVC is

QMAKE_CXXFLAGS += -P



回答2:


I could get Qt Creator to generate preprocessed files using one (or more) of the following options in the .pro file:

QMAKE_CFLAGS_DEBUG += -E

QMAKE_CFLAGS_RELEASE += -E

QMAKE_CXXFLAGS_DEBUG += -E

QMAKE_CXXFLAGS_RELEASE += -E

However, one bit of ugliness is that instead of putting the output into .i files it put them into the .o files (which the linker didn't much like...). Since this is presumably a 'one-off' situation for troubleshooting, I didn't look into how to clean that that up.

You may need to rerun 'qmake' before you rebuild, and you'll almost certainly need to run a "Clean Project" build before trying to generate the preprocessed output.



来源:https://stackoverflow.com/questions/4493293/preprocessor-output-on-qt-creator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!