This is ridiculous, im trying to create a sound bool to turn of in app sounds. I keep getting
Undefined symbols for architecture i386:
\"_kPlaySoundPrefsKey\",
First, ensure it is defined:
// AppDelegate.h
extern NSString* const kPlaySoundPrefsKey; // << declaration
// AppDelegate.m
NSString * const kPlaySoundPrefsKey = @"kPlaySoundPrefsKey"; // << definition
see also:
"extern const" vs "extern" only
3 questions about extern used in an Objective-C project
Linker error using extern "C" in Objective-C code
Thanks for your help guys
I added
NSString *kPlaySoundPrefsKey = @"playSoundKey";
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultDict];
to app delegate. That fixed it
I am also got the same error even if I am properly declared and define the extern const string , The problem is, my constant file not in the compile source list .
Make sure that your .m file appears in the "Compile Sources" Build Phase for your build target. Sometimes, adding files to a project in Xcode doesn't add all implementation files to the appropriate targets.
Hope this will helpful for some people. Refe: linker-error-undefined-symbols-symbols-not-found
When you declaring something as extern
you are telling the compiler the type AND that you will define it somewhere else. In your case you never define your variable.
So in your .h you would have:
extern NSString* kPlaySoundPrefsKey;
But in some .m you must also have
NSString* kPlaySoundPrefsKey = @"play_sounds"; // or some value
Since in your case these are constants you can also specify:
extern NSString* const kPlaySoundPrefsKey;
and
NSString* const kPlaySoundPrefsKey = @"play_sounds";
The addition of the const qualifier will cause a compiler error if someone ever writes something like
kPlaySoundPrefsKey = @"some_other_value";