4

I have been able to Archive on Xcode 4 successfully, but all of a sudden (??), I can't. The build fails with an invalid .pch file. The error is pasted in below (got from a reattempt with -Winvalid-pch, but what seems to be happening from the build log is that the precompiled header is not actually getting precompiled-- it's an iOS app, and goes straight from a CopyPNG step to a .m compile.

Could I have flipped something by accident? Nothing seems odd in my diff of the .pbxproj file.

cc1obj: warning: /Users/myname/Library/Developer/Xcode/DerivedData/Foo-afikuaovoaeqhreaaaakpafseuuv/Build/PrecompiledHeaders/Foo_Prefix-guqixmujoiaaaacwjctfkrztxmbz/Foo_Prefix.pch.gch: created by a different GCC executable
cc1obj: error: /Users/myname/Library/Developer/Xcode/DerivedData/Foo-afikuaovoaeqhreaaaakpafseuuv/Build/PrecompiledHeaders/Foo_Prefix-guqixmujoiaaaacwjctfkrztxmbz/Foo_Prefix.pch: No such file or directory
cc1obj: error: one or more PCH files were found, but they were invalid

The "Precompile Prefix Header" build setting is "Yes" for all configurations. Product->Clean doesn't help. Deleting the cached pch stuff under derived data doesn't fix it. Really seems like the whole "precompile" step is missing.

Another factoid: Enabling the setting "Increase Sharing of Precompiled Headers" DOES let it succeed. But I can find almost no reference to what this flag really does, and I have never used it before. And perhaps reasonably, the precompile step still doesn't show up when this happens.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204

2 Answers2

5

Have you cleaned and then rebuilt? Product Menu ==> Clean. Cleaning usually solves such problems, effectively instructing Xcode to compile everything, regardless of whether it thinks the previous build of that file is still valid.

If that fails, try wiping out the Derived Data folder for the project, at ~/Library/Developer/Xcode/DerivedData/YourProjectNamexxx where xxx is a uuid-style string.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • Yup, definitely (and I think all Archive builds generally do a clean first anyways). No change. I don't see the Precompile step at all in the build log. It just doesn't seem to be happening anymore. – Ben Zotto May 06 '11 at 02:53
  • 2
    @quixoto Bizarre. Try wiping out the Derived Data folder for the project, at `~/Library/Developer/Xcode/DerivedData/YourProjectNamexxx` where `xxx` is a uuid-style string – Matthew Frederick May 06 '11 at 04:19
  • Matthew: Thank you. I didn't do this specifically, but something like it (I checked out my tree into a fresh workspace and launched from there). I think Xcode had some confused state somewhere in there after switching branches. Although I can't figure out what, since the proj file was reasonable. I guess something stale in the intermediate products dirs somewhere. Thanks for your help. – Ben Zotto May 06 '11 at 04:54
  • @quixoto Great, glad it got you there! – Matthew Frederick May 06 '11 at 05:30
0

The approved answer is correct, just a note that it works only in some cases.

I just converted a project into workspace and changed Derived Data Location from default to Workspace-relative. Precompiled headers stopped working immediately and cleaning the old location didn't seem to make any difference. Well of cource, since it was the OLD location!

Workspace relative location seems to located inside folder, where the workspace file (myProject.xcworkspace) was saved. There's now new subfolder DerivedData, which contains folder named by workspace, which contains the familiar stuff.

Index folder contains the PrecompiledHeaders, which contains (finally) the several subfolders. Deleting all of those and recompiling forced precompiling happen.

JOM
  • 8,139
  • 6
  • 78
  • 111