73

Building an iPhone app, using:

  • Xcode 4.1
  • Base SDK iOS 4.3
  • Apple LLVM Compiler 2.1

I have started getting the following error:

fatal error: file '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/../lib/clang/2.1/include/stdint.h' has been modified since the precompiled header was built

I have tried reinstalling Xcode and OS X - no luck. What's causing this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
grfryling
  • 802
  • 1
  • 6
  • 9

11 Answers11

152

First try a clean build via the Product -> Clean menu (as of XCode 4.6.2).

If that still doesn't work then open the Organizer (from the menu select Window->Organizer). Once the Organizer is open, select Projects from the toolbar at the top of the window. On the left is a list of projects, select the one you are having a problem with.

The details panel (to the right of the list) will display the project name, location, status. The row beneath that shows where the Derived Data is located. Click the Delete... button the far right. A dialog will appear, click Delete.

You can also manually delete the Derived Data:

~/Library/Developer/Xcode/DerivedData/{project name + gobly-gook}

This directory contains built products and indexes for the project. It is OK to delete it because it only contains items generated by Xcode. Xcode will regenerate everything next time the project is opened.

logancautrell
  • 8,762
  • 3
  • 39
  • 50
  • 24
    Or you can simply "touch" your `.pch` file (or add and remove a char in it) so that it is recompiled, without the need to clean and rebuild all your project (this way the next build is quite faster) – AliSoftware Nov 12 '12 at 15:43
  • With older versions of Xcode this was the only way to fix it. – logancautrell Nov 15 '12 at 14:12
  • 1
    I had to also delete the Modules/&App dir under DerivedData after I changed a system header (accidentally). – VaporwareWolf Jun 16 '13 at 06:00
  • @AliSoftware when u say touch .pch, that just work because it is just the way to recompile entire project (which can be achieved by recompiling) as .pch is imported to all the class by default, thus touching it make entire project compile all over. – rptwsthi Mar 28 '14 at 18:44
  • @rptwsthi That's only true if you have one target and one project in your workspace. I usually have multiple projects, each one having its own `.pch` file; I don't want to "clean" and have **all** my projects (like my Pods) in my workspace recompile. Just changing the `.pch` of my app will only recompile all the files of my app, but **not** the external libraries (like my CocoaPods) and any other projects in my workspace. That's why for this particular issue I prefer to try and touch the `.pch` first, and only clean or remove DerivedData if the two former solutions do not work. – AliSoftware Mar 28 '14 at 19:32
  • First just clean Product - Clean – Nazir Jul 25 '14 at 12:30
  • 1
    OSX 10.10.2/Xcode 6.2. I was looking around in NSMutableArray.h for a method, and subsequently when I tried to Build my project, I got that error. I guess I must have changed something accidentally. My current project wouldn't build, no old projects would build, and a new project wouldn't build. No amount of cleaning worked for me, and going into the Organizer and deleting didn't work either. What worked for me was: 1) `$ cd ~/Library/Developer/Xcode/` 2) Then deleting the whole DerivedData folder: `~/Library/Developer/Xcode$ rm -rf DerivedData`. – 7stud Apr 18 '15 at 17:20
76

I was able to fix it in a much easier way, by simply choosing Product > Clean, then Product > Build from the Xcode menubar.

D-S
  • 897
  • 6
  • 12
  • 8
    +1. Did the same but a "deep clean" by pressing Cmd + Opt + Shft + K – jmstone617 Apr 26 '12 at 13:29
  • Please note that you will have to do Clean and Build on each target device that gives you the error. I had to do it for my simulator **and** for my iPad. – neoscribe Apr 10 '13 at 06:03
37

Deleting the DerivedData folder did not work for me when Archiving.

I had to look at Build Settings - Build Locations - Precompiled Header Cache Path and delete that folder.

For me that was:

/var/folders/_w/t0mj70hd1439tqgxff7_mtt00000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders
Ants
  • 1,338
  • 16
  • 27
16

I thought I would add a separate answer rather than a comment to Cryptognome's answer, because it is in fact a different solution when the issue comes from running xcodebuild. Like Cryptognome, I had the error come up with the command-line tool xcodebuild. As an alternative to manually going into the /var subfolders, I found that I could set my own cache for the shared PCH, which you can do by setting the environment variable SHARED_PRECOMPS_DIR, e.g as follows

xcodebuild -target Foo -configuration Release SHARED_PRECOMPS_DIR=/tmp/foo/SharedPCH

This way, I never get the error in automatic builds.

Note in the above command, I would also typically set the OBJROOT and SYMROOT env var to build also in /tmp. At the end, I clean things up.

charles
  • 11,212
  • 3
  • 31
  • 46
4

The xcodebuild command line tool sometimes fails with this error. This happened to me when I synched an svn workspace to an earlier build. The xcodebuild tool keeps its precompiled headers in the folder Ants mentioned:

/var/folders/... scrambled eggs .../-Caches-/com.apple.Xcode.503/SharedPrecompiledHeaders/

You have to look in the build command itself to see the actual folder name (-include /var/...), but it may be using several if you're building for different architectures (arm6, arm7, simulator, e.g.) So if you're having this problem with a command line build, just delete everything in /var/.../SharedPrecompiledHeaders.

David Gish
  • 750
  • 6
  • 14
  • 1
    That was the issue I had as well. Rather than relying on this default cache folder, I set my own cache in the same /tmp subfolder I used for the automatic build, which you can use by passing e.g. `SHARED_PRECOMPS_DIR=/tmp/foo/SharedPrecompiledHeaders` as an argument to `xcodebuild`. This way, I never get the error in automatic builds. – charles Nov 02 '11 at 03:16
3

Remove the contents for the Simulator by iOS Simulator > Reset Content and Settings... and hit Rest. This will remove any existing pre-compiled instances of the headers and resources. This worked for me

Sanjeev
  • 39
  • 5
3

Solution:

1)Product->Clean

2)Product->Build

Error Type:

a kind of Build error

One of the causes:

one might have changed the framework file. This sometimes happens when a change is made to a framework that another framework depends upon. The precompiled header cache gets out of sync, and Xcode is unable to compile the given project.

One of the Scenarios:

one might have chosen Jump To Definition and did some change after selecting a framework control.

Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241
  • 1
    Sure enough, I edited a System header file, which was listed in the error message. I was able to Time Machine restore the header, then clean and build, with success. – greg Sep 09 '13 at 01:59
  • it's really good solution otherwise one would have to do the aforementioned steps on every project in the system. – Durai Amuthan.H Sep 12 '13 at 09:24
1

I was able to get rid of this error simply by cleaning (command+shift+K) and rebuilding.

Noah Dyer
  • 407
  • 5
  • 10
1

I tried above all but no use. Finally I deleted Xcode and re installed again. Now it is working fine..

Xcode->delete->install again

It might help some one...

Narasimha Nallamsetty
  • 1,215
  • 14
  • 16
0

I had this error on cordova when I ran : cordova run ios

fatal error: file '/Users/.../cordova/platforms/ios/CordovaLib/CordovaLib_Prefix.pch' has been modified since the precompiled header
  '/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode/SharedPrecompiledHeaders/CordovaLib_Prefix-bfgesbulnxtdepfwgniffeysypgv/CordovaLib_Prefix.pch.pch' was built
note: please rebuild precompiled header
  '/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode/SharedPrecompiledHeaders/CordovaLib_Prefix-bfgesbulnxtdepfwgniffeysypgv/CordovaLib_Prefix.pch.pch'
1 error generated.

** BUILD FAILED **    

The following build commands failed:
    CompileC build/CordovaLib.build/Debug-iphoneos/CordovaLib.build/Objects-normal/armv7/NSDictionary+Extensions.o Classes/NSDictionary+Extensions.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    CompileC build/CordovaLib.build/Debug-iphoneos/CordovaLib.build/Objects-normal/armv7/CDVInvokedUrlCommand.o Classes/CDVInvokedUrlCommand.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler

I tried with clean and build but doesn't work, finaly I removed the folder '/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode' and works! This tip, may be help others

Crystian
  • 11
  • 1
  • A folder with a path like that seems like a painfully too-narrow example. It might be better to say "I finally removed the offending folder from the error, and it worked." – Gutblender Oct 08 '14 at 18:59
  • Yeap, you are right, but I don't found other case like mine, so I think it can be useful for others – Crystian Oct 12 '14 at 00:19
  • Exactly my point--if one takes your answer literally they'll wonder "why can't I find this path?" when the thing to take away from this is "I deleted the directory tree containing the precompiled headers (whatever that may be for you) and it worked." – Gutblender Oct 13 '14 at 01:19
0

Clean ways are not working for me, eventually I solved this issue by reinstall XCode.

Allen
  • 6,745
  • 5
  • 41
  • 59