Question

I'm writing an iOS game using Sprite Kit (so targeting iOS 7+) and I'm running into an issue when initializing a gameObject (custom class).

If I try and set a UUID for the game's ID, the build fails (see below for the error message); removing the call to the getUUID method fixes the problem, so I'm pretty sure that's where the problem lies.

The getUUID method is inside a helper class, which is imported in the Prefix.pch (and so should be available to all other file?).

Here's the helpers.h:

NSString *getUUID();

@interface helpers : NSObject

@end

And helpers.m:

@implementation helpers

+(NSString *)getUUID
{
    NSUUID *uuid = [NSUUID UUID];
    NSString *uuidString = [uuid UUIDString];

    return uuidString;
}

@end

Finally, here's what the gameObject.m looks like:

static NSString *gameID = nil;
static NSDate *gameStarted = nil;
static NSNumber *venue = nil;
static NSNumber *timerDuration = nil;
static NSArray *players = nil;
static NSArray *playerMoves = nil;
static NSNumber *winner = nil;

@implementation gameObject

+(void) initialize
{
    if(! gameID)
    {
        // generate a new guid for this game
        gameID = getUUID();
    }
}

@end

The error I'm getting is:

Undefined symbols for architecture i386:
  "_getUUID", referenced from:
      +[gameObject initialize] in gameObject.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've checked all the common fixes mentioned for this error on SO: my build settings architecture is set as arm64 arm7 arm7s, the files have their targets set correctly, and all my .m files are included in the build.

Any ideas where I've gone wrong? I'm still very new to Objective-C, so all of this is kind of flailing in the dark for me at the moment.

Was it helpful?

Solution

Your helpers.h file declares a function:

NSString *getUUID();

and the helpers.m file defines a class method:

+(NSString *)getUUID;

which is not the same. So you have to decide which one you want. For example, change the .h file to

@interface helpers : NSObject
+(NSString *)getUUID;
@end

and then call it like

gameID = [helpers getUUID];

(Side note: Class names usually start with a capital letter: "Helpers".)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top