0

I am pretty new to OSX programming, or to the use of ObjC. I've done a fair bit of C en C++ in the past, mainly in combination with VTK. I am trying to compile a very simple program, where I copied an init method from Apple demo code. I am pretty sure I'm forgetting something. My project is a default Cocoa app, and I made a class MyRoster which for some reason causes linking problems. The output during compilation is the following (if anyone needs more, just say so):

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)

The base app compiles fine; the problem is this modified init method:

- (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;
}

My question: why would this not link? The called methods are in standard Apple libraries, so what gives?

Many thanks,

Mark

Carelinkz
  • 936
  • 8
  • 27
  • Looks like you're missing a crucial framework – Paul R Sep 16 '11 at 10:58
  • Hi Paul, that's likely when you look at the problem, but as far as I know, I have a default Apple developer environment. To be honest, I am also not sure what I should look for, specifically. – Carelinkz Sep 16 '11 at 11:29
  • I see that you have `-framework Cocoa` in your compile line, try adding `-framework CalendarStore` in the same place in your makefile or what you are using. – epatel Sep 16 '11 at 11:40
  • Why don't you use Xcode? It would work in a blink. And then if you really insist on using the command line, you can inspect the commands that Xcode emits and find what you forgot. – Jean-Denis Muys Sep 16 '11 at 10:52
  • Thanks for answering Jean-Denis, Unfortunately, I am using Xcode (4), this is the output in the Issue navigator... – Carelinkz Sep 16 '11 at 11:30
  • OK, my bad. I misinterpreted your question. – Jean-Denis Muys Sep 16 '11 at 11:50

1 Answers1

1

It looks like you're missing the CalendarStore framework from your project - try adding /System/Library/Frameworks/CalendarStore.framework to your project.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Hm, that framework is there. Just checked with term. Let me try the full ical example from Apple. That will tell us if there is a problem with the environment or if I messed up... – Carelinkz Sep 16 '11 at 11:32
  • Sorry - I meant that you need to add this framework to your **project**, otherwise you will get link errors as per above. – Paul R Sep 16 '11 at 11:37
  • Ah I see. Is there a particular place in xcode4 to do this? Scanning through the build options for the ical demo code from Apple, I could not find it... – Carelinkz Sep 16 '11 at 12:08
  • I'm still on Xcode 3.2.6 so I can't tell you specifically what to do for Xcode 4, but typically you add frameworks in the same way that you add source files, i.e. just drag them to the project or use the Add to Project menu item. If you look in your project you probably have one or two system frameworks there already - just add the CalendarStore framework next to these. – Paul R Sep 16 '11 at 12:27
  • Excellent. I added the framework directory by drag-n-drop to the Frameworks directory in the project navigator tab, "frameworks" section, and Presto! Thanks a lot, I would never have thought this manual action was necessary. After all, I include an .h file from that framework.... Thanks again! – Carelinkz Sep 16 '11 at 18:34