I was defining a NSString to use as error domain in NSError and was copying how ASIHttpRequest was doing there's.
NSString* const FPServerAPIErrorDomain = @"FPServerAPIErrorDomain";
I put the const in its own .h file // FPServerAPICoordinatorConstants.h
#ifndef FirePlayer_FPServerAPICoordinatorConstants_h
#define FirePlayer_FPServerAPICoordinatorConstants_h
NSString* const FPServerAPIErrorDomain = @"FPServerAPIErrorDomain";
#endif
but when I included it in more than one .m
SomeFile.m
#import "FPServerAPICoordinatorConstants.h"
SomeOtherFile.m
#import "FPServerAPICoordinatorConstants.h"
I got linker error 'duplicate symbol'
ld: duplicate symbol _FPServerAPIErrorDomain in SomeFile.o and ....SomeOtherFile.o for architecture armv7
so I change the const to #define and it worked ok.
// FPServerAPICoordinatorConstants.h
#ifndef FirePlayer_FPServerAPICoordinatorConstants_h
#define FirePlayer_FPServerAPICoordinatorConstants_h
//THIS WAS TRIGGERING link errors
//NSString* const FPServerAPIErrorDomain = @"FPServerAPIErrorDomain";
//working OK
#define FPServerAPIErrorDomain @"FPServerAPIErrorDomain"
#endif
But is there a way to get the const in global space not to throw 'duplicate symbol'?
In your header file you want:
extern NSString *const FPServerAPIErrorDomain;
and then in an implementation file (so probably you want a FPServerAPICoordinatorConstants.m
) you will want:
NSString *const FPServerAPIErrorDomain = @"FPServerAPIErrorDomain";
Then you can import the header into multiple file and not get duplicate symbol errors.
[By the way, you don't need the #ifndef
guards if you're using #import
.]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With