OSX中的未定义符号,但标准的Apple方法?

时间:2011-09-16 10:46:17

标签: macos undefined ld icalendar

我对OSX编程或ObjC的使用都很陌生。我过去做过很多C en C ++,主要是与VTK结合使用。 我正在尝试编译一个非常简单的程序,我从Apple演示代码中复制了一个init方法。我很确定我忘记了什么。我的项目是一个默认的Cocoa应用程序,我创建了一个MyRoster类,由于某种原因导致链接问题。编译期间的输出如下(如果有人需要更多,只需这样说):

Ld /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug/Rooster.app/Contents/MacOS/Rooster normal x86_64
cd /Users/mark/Documents/Programming/Rooster
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug -F/Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug -filelist /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Intermediates/Rooster.build/Debug/Rooster.build/Objects-normal/x86_64/Rooster.LinkFileList -mmacosx-version-min=10.7 -framework Cocoa -o /Users/mark/Library/Developer/Xcode/DerivedData/Rooster-giqzgxqladmwyjepkqehtzkmuvyd/Build/Products/Debug/Rooster.app/Contents/MacOS/Rooster

Undefined symbols for architecture x86_64:
"_CalEventsChangedNotification", referenced from:
  -[MyTasksCalendar init] in MyTasksCalendar.o
"_CalEventsChangedExternallyNotification", referenced from:
  -[MyTasksCalendar init] in MyTasksCalendar.o
"_OBJC_CLASS_$_CalCalendarStore", referenced from:
  objc-class-ref in MyTasksCalendar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

基础应用程序编译正常;问题是这个修改过的init方法:

- (id)init
{
    self = [super init];
    if (self) {
        // Add the receiver as an observer of Calendar Store notifications
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventsChanged:) name:CalEventsChangedExternallyNotification object:[CalCalendarStore defaultCalendarStore]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventsChanged:) name:CalEventsChangedNotification object:[CalCalendarStore defaultCalendarStore]];

    // Create a predicate to use to fetch the events
    NSInteger year = [[NSCalendarDate date] yearOfCommonEra];
    startDate = [[NSCalendarDate dateWithYear:year month:1 day:1 hour:0 minute:0 second:0 timeZone:nil] retain]; 
    endDate = [[NSCalendarDate dateWithYear:year month:12 day:31 hour:23 minute:59 second:59 timeZone:nil] retain]; 
    NSPredicate *eventsForThisYear = [NSPredicate eventPredicateWithStartDate:startDate endDate:endDate calendars:[[CalCalendarStore defaultCalendarStore] calendars]];

    // Fetch all events for the current year
    events = [[NSMutableArray array] retain];
    [self addEventArray:[[CalCalendarStore defaultCalendarStore] eventsWithPredicate:eventsForThisYear]];
    }
    return self;
}

我的问题:为什么这不会链接?被调用的方法在标准的Apple库中,所以给出了什么?

非常感谢,

标记

1 个答案:

答案 0 :(得分:1)

您的项目似乎缺少CalendarStore框架 - 尝试将/System/Library/Frameworks/CalendarStore.framework添加到您的项目中。