Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 6, 2009, 10:28 AM   #1
RobRiley
macrumors member
 
Join Date: Feb 2009
Location: London
Send a message via AIM to RobRiley
NSWorkspace Basic Question

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..
RobRiley is offline   0 Reply With Quote
Old Feb 6, 2009, 10:40 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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).
kainjow is offline   0 Reply With Quote
Old Feb 6, 2009, 10:43 AM   #3
RobRiley
Thread Starter
macrumors member
 
Join Date: Feb 2009
Location: London
Send a message via AIM to RobRiley
Hey kainjow,

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

Thanks,
RobRiley is offline   0 Reply With Quote
Old Feb 6, 2009, 10:45 AM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Feb 6, 2009, 10:53 AM   #5
RobRiley
Thread Starter
macrumors member
 
Join Date: Feb 2009
Location: London
Send a message via AIM to RobRiley
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,
RobRiley is offline   0 Reply With Quote
Old Feb 6, 2009, 01:37 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Feb 7, 2009, 11:58 AM   #7
RobRiley
Thread Starter
macrumors member
 
Join Date: Feb 2009
Location: London
Send a message via AIM to RobRiley
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.
RobRiley is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
iTunes basic questions hkriffraff Mac Applications and Mac App Store 1 Dec 30, 2003 11:15 PM
IPOD Basic Questions cooks4 Buying Tips, Advice and Discussion (archive) 7 Nov 16, 2003 11:17 AM
Just upgraded - basic questions gundam Mac OS X 10.3 (Panther) Discussion 1 Nov 7, 2003 01:10 PM
Two very basic questions about Safari... furthur Mac Help/Tips 4 Apr 15, 2003 08:25 PM
A Real Basic Question... G4scott Mac Help/Tips 4 Jan 16, 2003 10:18 PM


All times are GMT -5. The time now is 05:05 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC