1

I'm building an app using Xcode 6 beta 6. I manually added a prefix file, and specified it in the Build Settings: $(SRCROOT)/$(PRODUCT_NAME)/MyApp-Prefix.pch. The file compiles, and the symbols defined there are not highlighted as undeclared in the editor. However, when I build the project, I get "undeclared identifier" errors for the macros defined in the prefix file. What's going on?

What I've tried:

  • Set Precompile Prefix Headers to YES (default is NO)
  • Clean the build folder and delete the derived data folder

What's interesting is the .pch file definitely gets compiled at build time. If I introduce a syntax error there, it gets called out in build results. If the pch file compiles OK, then the compiler starts acting like it can't find it when building the files that use it.

TotoroTotoro
  • 17,524
  • 4
  • 45
  • 76

3 Answers3

2

You should add the name of file into "Prefix Header" section without $(SRCROOT). Just set the Precompile Prefix Headers to YES is not enough.

  1. Make new file: ⌘cmd+N
  2. iOS/Mac > Other > PCH File > YourProject-Prefix.pch.
  3. Project > Build Settings > Search: "Prefix Header".
  4. Under "Apple LLVM 6.0" you will get the Prefix Header key.
  5. Type in: "MyApp/MyApp-Prefix.pch". ( without $(SRCROOT) !!! )
  6. Clean project: ⌘cmd+⇧shift+K
  7. Build project: ⌘cmd+B

For more detail look into https://stackoverflow.com/a/26126065/3628317 answer.

It works on XCode 6.1.

Community
  • 1
  • 1
levo4ka
  • 2,248
  • 1
  • 19
  • 32
0

As a first guess, you have a precompiled header that doesn't realize you've changed the .pch, so it's still using an old version of the precompiled file.

Clean your project, then go into Window > Organizer > Projects > $(PRODUCT_NAME) and delete the derived data.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
0

Sometimes you may just delete scheme or target and recreate a new one.

ManuQiao
  • 708
  • 8
  • 20