42

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

1
  • 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. Commented May 12, 2011 at 9:00

6 Answers 6

51

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

Sign up to request clarification or add additional context in comments.

4 Comments

You can even have a second assistant editor with the assembly output at the same time. Such an awesome feature.
Not that I think of it, this feature might be in the preview of Xcode 4.2.
~How can you have 2 assistant editors horizontally?!~ Nevermind.
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?
14

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

8 Comments

Which is in "Product" > "Generate Output".
I seem to get an empty file when I do this. Is the output actually going to some non-obvious place?
It will only show the preprocessed file after successful compilation - which defeats my purpose which is to debug preprocessing macros...
@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.
I have XCode 4.5 installed, which lists "Preprocessed File" under "Product" -> "Generate Output". This works fine, also if the file has compile errors.
|
13

@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

1 Comment

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?
5

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.

1 Comment

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.
1

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

Comments

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

3 Comments

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.
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: 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.