2011-12-26 156 views
1

虽然编译我接收到2个错误..Undefinded符号:链接错误

为i386硬件架构未定义符号:

“_IKImageBrowserNSURLRepresentationType”,从引用:

- [ATDesktopEntity imageRepresentationType ]在ATDesktopEntity.o

“.objc_class_name_CABasicAnimation”,引用自: ATColorView.o中的pointer-to-literal-objc-class-name ld:找不到体系结构的符号i386 clang:错误:链接器命令失败,退出代码1(使用-v查看调用)

我已经包括2个执行文件,其中我觉得这个问题是存在的......

#import "ATDesktopEntity.h" 
#import <Quartz/Quartz.h> 

#define THUMBNAIL_HIEGHT 180.0 
#define DEMO_MODE 0 

@implementation ATDesktopEntity 

+ (ATDesktopEntity *)entityForURL:(NSURL *)url { 

    NSString *typeIdentifier; 
    if ([url getResourceValue:&typeIdentifier forKey:NSURLTypeIdentifierKey 
     error:NULL]) { 
     NSArray *imageUTIs = [NSImage imageTypes]; 
     if ([imageUTIs containsObject:typeIdentifier]) { 
       return [[[ATDesktopImageEntity alloc] initWithFileURL:url] autorelease]; 
     }else if ([typeIdentifier isEqualToString:(NSString *)kUTTypeFolder]){ 
       return [[[ATDesktopFolderEntity alloc] initWithFileURL:url] autorelease]; 
     } 
    } 
    return nil; 
} 

@synthesize fileURL = _fileURL; 
@dynamic title; 

- (id)initWithFileURL:(NSURL *)fileURL 
{ 
    self = [super init]; 
    _fileURL = [fileURL retain]; 
    return self; 
} 

- (id)copyWithZone:(NSZone *)zone 
{ 
    id result = [[[self class] alloc] initWithFileURL:self.fileURL]; 
    return result; 
} 

- (NSString *)description 
{ 
    return [NSString stringWithFormat:@"%@ : %@", [super description], self.title]; 
} 

- (void)dealloc 
{ 
    [_fileURL release]; 
    [super dealloc]; 
} 

- (NSString *)title 
{ 
    NSString *result; 
    if ([self.fileURL getResourceValue:&result forKey:NSURLLocalizedNameKey 
     error:NULL]) { 
     return result; 
    } 
    return nil; 
} 

#pragma mark - 
#pragma mark NSPasteboardWriting support 

- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard 
{ 
    return [self.fileURL writableTypesForPasteboard:pasteboard]; 
} 

- (id)pasteboardPropertyListForType:(NSString *)type 
{ 
    return [self.fileURL pasteboardPropertyListForType:type]; 
} 

- (NSPasteboardWritingOptions)writingOptionsForType:(NSString *)type pasteboard: 
    (NSPasteboard *)pasteboard 
{ 
    if ([self.fileURL respondsToSelector:@selector(writingOptionsForType:pasteboard:)]) 
     { 
     return [self.fileURL writingOptionsForType:type pasteboard:pasteboard]; 
    }else{ 
     return 0; 
    } 
} 

#pragma mark - 
#pragma mark NSPasteboardReading support 

+ (NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard 
{ 
    return [NSArray arrayWithObjects:(id)kUTTypeFolder, (id)kUTTypeFileURL, nil]; 
} 
+ (NSPasteboardReadingOptions)readingOptionsForType:(NSString *)type pasteboard: 
    (NSPasteboard *)pasteboard 
{ 
    return NSPasteboardReadingAsString; 
} 

- (id)initWithPasteboardPropertyList:(id)propertyList ofType:(NSString *)type 
{ 
    [self release]; 
    self = nil; 

    NSURL *url = [[[NSURL alloc] initWithPasteboardPropertyList:propertyList 
     ofType:type] autorelease]; 
    NSString *urlUTI; 
    if ([url getResourceValue:&urlUTI forKey:NSURLTypeIdentifierKey error:NULL 
     ]) { 
     if ([[NSImage imageTypes] containsObject:urlUTI]) { 
      self = [[ATDesktopImageEntity alloc] initWithFileURL:url]; 
     }else if ([urlUTI isEqualToString:(id)kUTTypeFolder]) { 

      self = [[ATDesktopFolderEntity alloc] initWithFileURL:url]; 
     } 
    } 
    return self; 
} 

#pragma mark - 

- (NSString *)imageUID 
{ 
    return [NSString stringWithFormat:@"%p", self]; 
} 

- (NSString *)imageRepresentationType 
{ 
    return IKImageBrowserNSURLRepresentationType; 
} 

- (id)imageRepresentation 
{ 
    return self.fileURL; 
} 

- (NSUInteger)imageVersion 
{ 
    return 0; 
} 

- (NSString *)imageTitle 
{ 
    return self.title; 
} 

- (NSString *)imageSubtitle 
{ 
    return nil; 
} 

- (BOOL)isSelectable 
{ 
    return YES; 
} 

@end 


@interface ATDesktopImageEntity() 

@property (readwrite, retain) NSImage *thumbnailImage; 

@property (readwrite) BOOL imageLoading; 

@end 

static NSOperationQueue *ATSharedOperationQueue() 
{ 
    static NSOperationQueue *_ATSharedOperationQueue = nil; 
    if (_ATSharedOperationQueue == nil) { 
     _ATSharedOperationQueue = [[NSOperationQueue alloc] init]; 
     [_ATSharedOperationQueue setMaxConcurrentOperationCount:2]; 
    } 
    return _ATSharedOperationQueue; 
} 

@implementation ATDesktopImageEntity 

- (id)initWithFileURL:(NSURL *)fileURL 
{ 
    self = [super initWithFileURL:fileURL]; 

    static NSInteger lastColorIndex = 0; 
    NSColorList *colorList = [NSColorList colorListNamed:@"Crayons"]; 
    NSArray *keys = [colorList allKeys]; 
    if (lastColorIndex >= keys.count) { 
     lastColorIndex = 0; 
    } 
    _fillColorName = [[keys objectAtIndex:lastColorIndex++] retain]; 
    _fillColor = [[colorList colorWithKey:_fillColorName] retain]; 
    self.title = [super title]; 
    return self; 
} 

- (void)dealloc 
{ 
    [_thumbnailImage release]; 
    [_image release]; 
    [_fillColor release]; 
    [_fillColorName release]; 
    [_title release]; 
    [super dealloc]; 
} 

@synthesize fillColor = _fillColor; 
@synthesize fillColorName = _fillColorName; 
@synthesize imageLoading = _imageLoading; 
@synthesize image = _image; 
@synthesize thumbnailImage = _thumbnailImage; 
@synthesize title = _title; 

static NSImage *ATThumbnailImageFromImage(NSImage *image) 
{ 
    NSSize imageSize = [image size]; 
    CGFloat imageAspectRatio = imageSize.width/imageSize.height; 

    NSSize thumbnailSize = NSMakeSize(THUMBNAIL_HIEGHT * imageAspectRatio, 
     THUMBNAIL_HIEGHT); 
    NSImage *thumbnailImage = [[NSImage alloc] initWithSize:thumbnailSize]; 
    [thumbnailImage lockFocus]; 
    [image drawInRect:NSMakeRect(0, 0, thumbnailSize.width, thumbnailSize. 
     height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; 
    [thumbnailImage unlockFocus]; 

#if DEMO_MODE 
    usleep(250000); 
#endif 

    return [thumbnailImage autorelease]; 
} 

- (NSImage *)thumbnailImage 
{ 
    if (self.image != nil && _thumbnailImage == nil) { 
     _thumbnailImage = [ ATThumbnailImageFromImage(self.image) retain]; 
    }else if (self.image == nil && !self.imageLoading) { 

     [self loadImage]; 
    } 
    return _thumbnailImage; 
} 

- (void)loadImage 
{ 
    @synchronized (self) { 
     if (self.image == nil && !self.imageLoading) { 
      self.imageLoading = YES; 

      [ATSharedOperationQueue() addOperationWithBlock:^(void) { 
       NSImage *image = [[NSImage alloc] initWithContentsOfURL:self.fileURL]; 
       if (image != nil) { 
        NSImage *thumbnailImage = ATThumbnailImageFromImage(image); 

        @synchronized (self) { 
         self.imageLoading = NO; 
         self.image = image; 
         self.thumbnailImage = thumbnailImage; 
        } 
        [image release]; 
       }else{ 
        @synchronized (self) { 
         self.image = [NSImage imageNamed:NSImageNameTrashFull]; 
        } 
       } 
      }]; 
     } 
    } 
} 
@end; 


@implementation ATDesktopFolderEntity 

- (void)dealloc 
{ 
    [_children release]; 
    [super dealloc]; 
} 

@dynamic children; 

- (NSMutableArray *)children 
{ 
    NSMutableArray *result = nil; 

    @synchronized (self) { 

     if (_children == nil && self.fileURL != nil) { 
      NSError *error = nil; 

      NSArray *urls = [[NSFileManager defaultManager] 
          contentsOfDirectoryAtURL:self.fileURL 
          includingPropertiesForKeys:[NSArray 
            arrayWithObjects:NSURLLocalizedNameKey, nil] 
               options:   
               NSDirectoryEnumerationSkipsHiddenFiles | 
         NSDirectoryEnumerationSkipsSubdirectoryDescendants error:&error]; 
      NSMutableArray *newChildren = [[NSMutableArray alloc] initWithCapacity:urls.count]; 

      for (NSURL *url in urls) { 
       NSString *typeIndentifier; 
       if ([url getResourceValue:&typeIndentifier forKey: 
        NSURLTypeIdentifierKey error:NULL]) { 
        ATDesktopEntity *entity = [ATDesktopEntity entityForURL:url]; 
        if (entity) { 
         newChildren addObject:entity]; 
        } 
       } 
      } 
      _children = newChildren; 
     } 
     result = [[_children retain] autorelease]; 
    } 
    return result; 
} 

- (void)setChildren:(NSMutableArray *)value 
{ 
    @synchronized (self) { 
     if (_children != value) { 
      [_children release]; 
      _children = [value retain]; 
     } 
    } 
} 
@end 

NSString *const ATEntityPropertyNamedFillColor = @"fillColor"; 
NSString *const ATEntityPropertyNamedFillColorName = @"fillColorName"; 
NSString *const ATEntityPropertyNamedImage = @"image"; 
NSString *const ATEntityPropertyNamedThumbnailImage = @"thumbnailImage"; 

第二个文件..

#import "ATColorView.h" 

#import <Quartz/Quartz.h> 

@implementation ATColorView 

+ (id)defaultAnimationForKey:(NSString *)key{ 
    if ([key isEqualToString:@"backgroundColor"]) { 
     return [CABasicAnimation animation]; 
    } 
    return [super defaultAnimationForKey:key]; 
}      

- (void)dealloc 
{ 
    self.backgroundColor = nil; 
    [super dealloc]; 
} 

@synthesize backgroundColor; 
@synthesize drawBorder; 

- (CGColorRef)createBackgroundColorRef 
{ 
    CGFloat components[backgroundColor.numberOfComponents]; 
    [backgroundColor getComponents:components]; 
    return CGColorCreate([[backgroundColor colorSpace] CGColorSpace],components); 
} 

- (void)setBackgroundColor:(NSColor *)value 
{ 
    if (backgroundColor != value) { 
     [backgroundColor release]; 
     backgroundColor = [value retain]; 
     if (self.layer == nil) { 
      CGColorRef backgroundColorRef = [self createBackgroundColorRef]; 
      self.layer.backgroundColor = backgroundColorRef; 
      CGColorRelease(backgroundColorRef); 
     } 
     [self setNeedsDisplay:YES]; 
    } 
} 

- (void)drawRect:(NSRect)r 
{ 
    NSColor *color = [self backgroundColor]; 
    if (color) { 
     [color set]; 
     NSRectFill(r); 
    } 
    if (self.drawBorder) { 
     [[NSColor lightGrayColor] set]; 
     NSFrameRectWithWidth(self.bounds, 1.0); 
    } 
    if (self.window.firstResponder == self) { 
     NSSetFocusRingStyle(NSFocusRingOnly); 
     NSRectFill(self.bounds); 
    } 
} 

- (void)mouseUp:(NSEvent *)theEvent 
{ 
    NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; 
    if (NSPointInRect(point, self.bounds) && self.action) { 
     [NSApp sendAction:self.action to:self.target]; 
    } 
} 

+ (Class)cellClass { 
    return [NSActionCell class]; 
} 

@end 

回答

1

改线#import <Quartz/Quartz.h>#import <QuartzCore/QuartzCore.h>

另外请确保您已将这些库和框架链接到您的项目。

欲了解更多信息,请查看本post

+0

谢谢你,做到了...... – dec 2011-12-26 07:14:45

+0

嘿最后thing..Now当你说链接库和框架,你指的是框架文件当你开始一个新项目时加载?如果不是他们是什么文件? – dec 2011-12-26 07:21:35

+0

是的,我的意思是框架。另外,如果我们添加任何静态库,那也需要链接到我们的项目。这就是为什么我把两者结合起来 – Ilanchezhian 2011-12-26 07:26:53