11

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user549099
  • 113
  • 1
  • 4

2 Answers2

19

-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
Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
1

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.

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • Thanks for your reply. I was unable to use this due to the side-effect, so I used the solution posted above – user549099 Dec 22 '10 at 20:12