架构i386的未定义符号:链接器错误

时间:2011-12-26 06:39:14

标签: objective-c xcode4.2

编译时我收到了2个错误..

架构i386的未定义符号:

" _IKImageBrowserNSURLRepresentationType",引自:

- ATDesktopEntity.o中的[ATDesktopEntity imageRepresentationType]

" .objc_class_name_CABasicAnimation",引自:  ATColorView.o中指向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 个答案:

答案 0 :(得分:1)

将第#import <Quartz/Quartz.h>行更改为#import <QuartzCore/QuartzCore.h>

还要确保已将这些库和框架链接到项目中。

有关详细信息,请查看此post