Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RobRiley

macrumors member
Original poster
Feb 4, 2009
35
0
London
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:

Code:
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:

Code:
 ".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:

Code:
#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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors member
Original poster
Feb 4, 2009
35
0
London
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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors member
Original poster
Feb 4, 2009
35
0
London
It's already there. I've broken it down into the simplest form to try and diagnose the problem. Here is my header file:

Code:
#import <Cocoa/Cocoa.h>

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

And here is my implementation file:

#import "AppController.h"

Code:
@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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors member
Original poster
Feb 4, 2009
35
0
London
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.