Preprocessor output on Qt Creator

旧巷老猫 提交于 2019-12-01 03:37:25

-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

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.

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