30

This problem is very similar to this one: Xcode 4 Preview 4 displays "Build Succeeded" but with errors

The different solutions proposed at the link doesn't work. I tried using product clean, deleteing the Derived Data, restart XCode and the Mac, but the problem still appears.

It seems that all the error are linked to the project's precompiled header : although the PCH is working fine and has no error in itself, the errors reported look like the pch is not found for this specific file. Also sometimes, while the build progresses, the errors appear and disappear randomly. Anyone have an idea on this?

enter image description here

The error only appear in the file(s) opened in the editor. If I close the file's in xcode but keep the project open, then no error are reported at all.

Cœur
  • 37,241
  • 25
  • 195
  • 267
XGouchet
  • 10,002
  • 10
  • 48
  • 83
  • A screenshot or copy of the error might help. Otherwise, you could try and modify the pch file so that it will detect the change and re-compile it, possibly clearing any errors you might have for good. – Bill Burgess Dec 19 '12 at 14:22
  • The errors are mostly "Use of undeclared identifier XXX", and the XXX identifier is defined in the pch using #define – XGouchet Dec 21 '12 at 10:08
  • You're assuming that the .pch file is found/fine. Try putting in an explicit '#warning "This is BAD!"' in your .pch file and then re-compile. If you don't get the warning then Xcode isn't finding your .pch file. – geowar Dec 21 '12 at 16:50
  • The constants defined in the pch are used all over the project, and the project builds and run completely fine. – XGouchet Dec 21 '12 at 17:20

9 Answers9

67

Cleaning, closing, restarting - none worked for me.

A simple touch/edit to the pch file in question resolved the issue.

kball
  • 4,923
  • 3
  • 29
  • 31
27

Have you tried cleaning the build folder?

In XCode, open the Product menu then hold down option. Clean should change to Clean Build Folder.

Edit:

You can also press + + + K

Edward Loveall
  • 1,983
  • 1
  • 19
  • 34
Lance
  • 8,872
  • 2
  • 36
  • 47
  • Tried that immediately, did not work. This problem is chasing two of my projects. Shows same "not defined" error in both projects for the same header file that is clearly included. This happened out of the blue, no changes to system or to compiler install. – Cerniuk Nov 07 '17 at 14:01
  • Wow, this worked for me. I've been using Xcode for years and never knew about this. I just restart Xcode. The discoverability of this secret key mapping is terrible! – johnbakers Mar 07 '21 at 13:25
5

I had this same issue, and neither types of cleans helped. I also tried deleting the build folder, restarting xcode, etc and for me what finally solved the issue was to remove the files that the errors referenced and re-add them.

Additionally, I investigated the error after the fact, and the issue seems to be XCode's "Show Live Issues" feature. (This can be unchecked in the preferences, this also solved the issue but was unsatisfactory as a solution as I've grown to enjoy xcode's live code sense.)

hatunike
  • 1,967
  • 1
  • 19
  • 26
  • 1
    I couldn't just re-add all the files since so many were affected, but unchecking "Show live issues" in Xcode prefs fixed the issue. I'd rather have issues not show up until I build than have dozens of fake ones hanging around all the time. – aednichols Apr 04 '14 at 15:23
2

Cleaning the product folder and restarting didn't help me. I started seeing this after I deleted the DerivedData folder. I was able to "fix" by doing :

  1. Clean build.
  2. Archive
  3. Build
Mustafa
  • 5,307
  • 1
  • 20
  • 19
1

I'm not sure adding a define to the pch will work as you think. Try creating a Constants header and add your defines there. Then you can include the import statement in your pch file and it should work that way.

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
  • the pch does just that, importing other .h with defines. This worked fine until one day it started seeing errors which dont exist. I found out that the only fake errors it sees are in the opened file. – XGouchet Jan 07 '13 at 10:52
1
Go to xcode install folder like below.

/Users/vinod/Library/Developer/Xcode

Step-1 Quit the xcode

Step-2 Delete the DerivedData Folder

Step-3 Now open the project and clean it all issue resolved.

mobility
  • 37
  • 1
  • 10
0

to add my two cents: my solution was to slightly change the order of imports in the pch file.

Maybe this is related to simply edit the file, but I've tried to "touch" it and edit and the only "thing" that did fix the problem was to move some import before others.

superandrew
  • 1,741
  • 19
  • 35
0
  1. Delete derived data
  2. Clean project
  3. Quit Xcode and reopen it.
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
0

Removing the last #import from .pch file, build the app then putting it back and building it again did the trick for me.

If you still see the errors then you could repeat this step for last two imports, last three imports and so on.

Swati Gupta
  • 354
  • 1
  • 9