Question

I have the following code:

@interface UIAcceleration (Simulation)

- (id) initWithTimestamp:(NSTimeInterval)aTimeStamp
                     X:(UIAccelerationValue)ax
                     Y:(UIAccelerationValue)ay
                     Z:(UIAccelerationValue)az;

@end

@implementation UIAcceleration (Simulation)

-(id)initWithTimestamp:(NSTimeInterval)aTimeStamp
                     X:(UIAccelerationValue)ax
                     Y:(UIAccelerationValue)ay
                     Z:(UIAccelerationValue)az 
{
    if (self = [super init])
    {
        timestamp = aTimeStamp;
        x = ax;
        y = ay;
        z = az;
    }

    return self;
}       

@end

when compiling this for simulator SDK everything works fine. When compiling for device SDK I get the following linker error:

  "_OBJC_IVAR_$_UIAcceleration.x", referenced from:
      _OBJC_IVAR_$_UIAcceleration.x$non_lazy_ptr in UIAcceleration+IRowAdditions.o
  "_OBJC_IVAR_$_UIAcceleration.y", referenced from:
      _OBJC_IVAR_$_UIAcceleration.y$non_lazy_ptr in UIAcceleration+IRowAdditions.o
  "_OBJC_IVAR_$_UIAcceleration.z", referenced from:
      _OBJC_IVAR_$_UIAcceleration.z$non_lazy_ptr in UIAcceleration+IRowAdditions.o
  "_OBJC_IVAR_$_UIAcceleration.timestamp", referenced from:
      _OBJC_IVAR_$_UIAcceleration.timestamp$non_lazy_ptr in AccelerometerSimulation.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

What am I doing wrong? What is different between linking against Simulator frameworks (namely UIKit) and linking against device frameworks?

Was it helpful?

Solution 3

Ok, as none of the answers given helped, I did something diferent.

I created a class with exactly the same interface as UIAcceleration. Because both of them have the same memory layout, I can safely cast between pointers of UIAcceleration and my class. At least as long as gcc wants.

OTHER TIPS

I think you probably included only the simulator version of the UIKit framework. I'm not so sure about this, but go to the left pane in Xcode and under the Frameworks folder, right click on UIKit.framework and Get Info. On mine, the path is /System/Library/Frameworks/UIKit.framework and right under that it says Path Type: "Relative to Current SDK". That should automatically pull the correct framework depending on what you're building for.

Worth a check.

This may be related to this issue with categories on the iPhone. Try adding -ObjC (iPhone OS 2.x) and -all_load (iPhone OS 3.0) to your "Other Linker Flags".

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