Precompiled Header with Constants issue
Asked Answered
G

4

8

I have a few constants files "Constants.h" in my project that I am including in the Prefix.pch file to be available to all the classes in my project. They just contain a bunch of #define statements.

My classes don't recognize these constants (no autocomplete) and Xcode gives me "Undeclared Identifier" errors every time I use them. However when I run the project everything works fine (set to ignore errors).

Is there any way I can get rid of these warnings? #pragma ignore them in the prefix file or something? I've tried many options, including setting "precompile prefix header" to NO in build settings.

Any ideas?

EDIT: I have tried deleting derived data and cleaning / deleting build folder to no avail.

It might be worth noting that I have 3 targets in my project, and another project within this project.

Also, some of the #imports import normal classes. Like a category extension on UIFont and an Analytics class. Could this affect it?

Galeiform answered 16/8, 2012 at 15:53 Comment(6)
"Undeclared identifier" is an error, not a warning. You cannot compile and run a program using undeclared identifiers.Uhhuh
Edited to correct that, I meant error. I have it set to ignore errors so the program still compiles and runs fine, xcode just gives me these errors when I'm editing code.Galeiform
And it doesn't recognize them right away after building, usually only when i'm inside a class that uses those constants does it start seeing the 'errors'Galeiform
What exactly have you set to "ignore errors"? You cannot compile and run a program containing errors.Uhhuh
it's better to "answer your own question" than to edit the question itself and mark it as "solved", so that it doesn't appear in the "unanswered questions" list.Gerson
I couldn't answer my own question because it wouldn't let me, because "new users cannot answer their own questions within 4 hours of posting"Galeiform
G
0

I had a preprocessor macro in one of my targets that I moved from 'preprocessor macros' to 'preprocessor macros not used in precompiled headers' and that solved the problem.

Galeiform answered 17/8, 2012 at 21:6 Comment(0)
P
10

To fix this, I had to change the 'Precompile Prefix Header' flag to NO in my target's Build Settings. By doing this you'll lose any build performance achieved by having a cached compiled header file, but in my case, my Prefix Header is pretty small so I wont see a hit in the time it takes to build.

Photofinishing answered 19/12, 2012 at 21:26 Comment(1)
This solved it for me as well, but it does make compiling substantially slower. Any way to avoid that?Crop
W
3

Try deleting the project derived data. Xcode sometimes needs to re-index your project to remove "errors" such as this.

Organizer > Projects > Your Project

Click on the "Delete" button to the right of the Derived Data row.

Immediately quit Xcode, and then reopen.

Weatherwise answered 16/8, 2012 at 17:12 Comment(2)
Have tried that many times. Also tried deleting build folder, cleaning etc. Keeps coming back.Galeiform
Solved my problem i was stuck on in for an hour.Erlanger
C
2

I had the PCH file importing .h file with a lot of macros (specifically, I use the MJGAvailability header that warns when I use features that are newer than my deployment target). Replacing:

#import "MJGAvailability.h"

with

#include "MJGAvailability.h"

solved this issue for me.

Crop answered 11/1, 2014 at 14:57 Comment(0)
G
0

I had a preprocessor macro in one of my targets that I moved from 'preprocessor macros' to 'preprocessor macros not used in precompiled headers' and that solved the problem.

Galeiform answered 17/8, 2012 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.