41

I want to check the output of the preprocessor for some files. How can I view the preprocessor's output in Xcode?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MacMark
  • 6,239
  • 2
  • 36
  • 41
  • 1
    Since "Preprocess" and "Show Assembly Code" commands were available in Xcode 3 we should file bug reports about Xcode 4 regarding this missing feature to Apple. – MacMark May 12 '11 at 09:00

6 Answers6

50

You can choose the "Show the Assistant editor" view in the top right set of buttons in the toolbar.

enter image description here

Then, at the top of the right-hand editor you can click the little Related Files button and then either choose Preprocess or Assembly.

enter image description here

You can see an example of both the preprocessor output and generated assembly code all side-by-side here:

enter image description here

Steven Hepting
  • 12,394
  • 8
  • 40
  • 50
  • 1
    You can even have a second assistant editor with the assembly output at the same time. Such an awesome feature. – Tim Rupe Jul 01 '11 at 20:13
  • Not that I think of it, this feature might be in the preview of Xcode 4.2. – Tim Rupe Jul 05 '11 at 18:23
  • ~How can you have 2 assistant editors horizontally?!~ [Nevermind](https://stackoverflow.com/a/47185446/865175). – Iulian Onofrei Mar 01 '19 at 08:41
  • In XCode 11, when I switch the assistant to preprocess (or assembly, for that matter), it gives me a plist xml output with the Apple clang version and not much else. Any ideas? – Nathan Friedly Apr 06 '20 at 19:07
15

Xcode 4.1 features now "Preprocessor or Assembly Output". All be happy!

MacMark
  • 6,239
  • 2
  • 36
  • 41
  • 8
    Which is in "Product" > "Generate Output". – Chris Burt-Brown Dec 01 '11 at 10:15
  • I seem to get an empty file when I do this. Is the output actually going to some non-obvious place? – Uncommon Mar 26 '12 at 18:43
  • 3
    It will only show the preprocessed file after successful compilation - which defeats my purpose which is to debug preprocessing macros... – Eric Chen Apr 09 '12 at 05:37
  • @e_x_p: Same here. I'm having a linking issue within code generated by macro, I'd really like to see what this code looks like but I don't have the options mentioned in this answer because I cannot successfully compile. – Nic Foster Oct 12 '12 at 18:08
  • I have XCode 4.5 installed, which lists "Preprocessed File" under "Product" -> "Generate Output". This works fine, also if the file has compile errors. – fishinear Nov 14 '12 at 17:45
  • Is there a way to get the Objective C source annotation with the disassembly? The disassembly is nice, but without context it is not very decipherable. – Cris Jul 15 '13 at 21:07
  • FYI, In Xcode 5 it's in Product / Perform Action / Preprocess. – algal Jan 27 '14 at 20:51
11

@whoKnows's excellent and concise answer applies to Xcode 6 users. The preprocessor menu seems to wander all over the place from one Xcode version to another.

To recap: XCode 6 users can view preprocessor output by pulling down this menu:

Product -> Perform Action -> Preprocess

as illustrated in the accompanying screenshot. I couldn't find this anywhere in the Xcode documentation.

(I hope this helps. I would have preferred to simply add a comment to @whoKnows's answer, but I don't have privileges for that yet.)

screenshot of menu pulldowns for viewing preprocessor output

jt bullitt
  • 300
  • 3
  • 14
4

You can always just run the preprocessor on the files from the command line using the -E flag with llvm-gcc (this is what Xcode 4 uses as a replacement for GCC). Something like this:

llvm-gcc -E -o output.preprocess input.c

Then you can just open up the output file in a text editor.

Kyle
  • 1,620
  • 14
  • 25
  • 1
    Most of the time, this alone won't cut it; the #include paths need to be defined, for example. You probably have to dig into the build log to figure all the right command line options, but in theory this will get you there. – benzado May 25 '11 at 18:31
1

<menubar> -> Product -> Perform action -> Preprocess <the name of your file>

whoKnows
  • 905
  • 2
  • 9
  • 27
0

I did not find any way too. Seems that "Preprocess" feature is missing in Xcode 4. I haven't read any document from apple, where they mentioned anything about this.

Following uri might help you: http://pilky.me/view/15

Learner
  • 672
  • 6
  • 9
  • 1
    When I wrote the above information, it was quite correct. But I understand it was not an answer as I had no privileges to add comment and I wanted to MacMark let know features he is looking for are missing. Ok, now above information are no longer valid for Preprocessed/Assembly output, I am now using Xcode 4.0.2. Users can follow Steven Hepting answer as well as select menu "Product", then select option "Generate Output" then "Generate Preprocessed File" or "Generate Assembly File". Hope this information helps users not to misunderstand above information. – Learner Jul 02 '11 at 11:06
  • I am using Xcode 4.0.2 (Build 4A2002a) and do not see either option you describe, not in the "Product" menu (no "Generate" item of any kind) nor in the "little suit and bow-tie" popup that Steven Hepting describes. – SteveCaine Jul 22 '11 at 18:31
  • 1
    @SteveCaine: I have updated my Xcode and now checked that at the moment I am using Xcode Version 4.2 (Build 4C104). And Product/Generate Output options are available here. Sorry If my previous comment gives you wrong-information. – Learner Jul 25 '11 at 17:26