PDA

View Full Version : NSWorkspace Basic Question




RobRiley
Feb 6, 2009, 10:28 AM
Hi,

Just trying to get some basic NSWorkspace stuff going but can't compile my app. I thought it was my code so I lifted the following from another site and still get the same errors:

NSString * path = @"/Developer/About Xcode Tools.pdf";
NSURL * fileURL = [NSURL fileURLWithPath: path];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
[ws openFile:[fileURL path] withApplication:@"Safari"];

The errors are:

".objc_class_name_NSWorkspace", referenced from:
literal-pointer@__OBJC@__cls_refs@NSWorkspace in AppController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I read that it could be that I'm not including the correct libraries. I am including the following in my header file:

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
#import <AppKit/AppKit.h>

Anyone know what the problem is?

Thanks in advance..



kainjow
Feb 6, 2009, 10:40 AM
The Cocoa framework includes AppKit and Foundation, so including those again is unnecessary.

How are you compiling? Xcode or Terminal? It looks like you aren't probably linking against the Cocoa or AppKit framework (NSWorkspace is part of AppKit).

RobRiley
Feb 6, 2009, 10:43 AM
Hey kainjow,

I'm compiling in XCode. Thanks for the tip re.including files. So how do I link against those frameworks correctly?

Thanks,

kainjow
Feb 6, 2009, 10:45 AM
If this is a standard Cocoa application it should already be included. If not, then you need to add the Cocoa framework into the Frameworks group.

Under Targets > yourapp, there is a group Link Binary With Libraries. You should see the framework here once you've added it to the Frameworks group.

RobRiley
Feb 6, 2009, 10:53 AM
It's already there. I've broken it down into the simplest form to try and diagnose the problem. Here is my header file:

#import <Cocoa/Cocoa.h>

@interface AppController : NSObject {
}
- (IBAction)Test:(id)sender;
@end

And here is my implementation file:

#import "AppController.h"

@implementation AppController
- (IBAction)Test:(id)sender{
NSString * path = @"/Developer/About Xcode Tools.pdf";
NSURL * fileURL = [NSURL fileURLWithPath: path];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
[ws openFile:[fileURL path] withApplication:@"Safari"];
}
@end

Is my code wrong?

Thanks,

kainjow
Feb 6, 2009, 01:37 PM
It's not your code. Maybe if your project is tiny you could upload it here. If that's not the problem then somehow your Xcode installation is hosed, but that would be odd.

RobRiley
Feb 7, 2009, 11:58 AM
Well strangely I've just pasted the code into a new project and it works.. so not sure what the problem was. I'll go back and figure it out when I've got a spare week! Thanks for all your help.