Xcode Preprocessor Output
Asked Answered
U

6

42

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

Undulation answered 9/5, 2011 at 12:43 Comment(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.Undulation
U
15

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

Undulation answered 1/8, 2011 at 15:55 Comment(7)
Which is in "Product" > "Generate Output".Superdominant
I seem to get an empty file when I do this. Is the output actually going to some non-obvious place?Affirmative
It will only show the preprocessed file after successful compilation - which defeats my purpose which is to debug preprocessing macros...Rete
@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.Chere
I have XCode 4.5 installed, which lists "Preprocessed File" under "Product" -> "Generate Output". This works fine, also if the file has compile errors.Vedis
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.Transmarine
FYI, In Xcode 5 it's in Product / Perform Action / Preprocess.Nadia
B
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

Bellbottoms answered 1/7, 2011 at 19:28 Comment(4)
You can even have a second assistant editor with the assembly output at the same time. Such an awesome feature.Catastrophism
Not that I think of it, this feature might be in the preview of Xcode 4.2.Catastrophism
~How can you have 2 assistant editors horizontally?!~ Nevermind.Curry
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?Deal
U
15

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

Undulation answered 1/8, 2011 at 15:55 Comment(7)
Which is in "Product" > "Generate Output".Superdominant
I seem to get an empty file when I do this. Is the output actually going to some non-obvious place?Affirmative
It will only show the preprocessed file after successful compilation - which defeats my purpose which is to debug preprocessing macros...Rete
@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.Chere
I have XCode 4.5 installed, which lists "Preprocessed File" under "Product" -> "Generate Output". This works fine, also if the file has compile errors.Vedis
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.Transmarine
FYI, In Xcode 5 it's in Product / Perform Action / Preprocess.Nadia
L
12

@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

Leatheroid answered 20/6, 2015 at 11:43 Comment(1)
When I do this in XCode 11, I'm getting a plist xml output with the Apple clang version and not much else. Any ideas?Deal
P
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.

Postwar answered 10/5, 2011 at 18:13 Comment(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.Biauriculate
S
1

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

Section answered 19/4, 2015 at 13:46 Comment(0)
C
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

Christiachristian answered 10/5, 2011 at 17:18 Comment(3)
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.Christiachristian
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.Hideous
@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.Christiachristian

© 2022 - 2024 — McMap. All rights reserved.