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

Similar Threads
thread Thread Starter Forum Replies Last Post
Snow Leopard File Vault Question and Basic System Password Question & Time Machine? GordonGekko999 Mac Basics and Help 0 Oct 25, 2013 06:06 AM
Very basic stupid question maryjolemmon Mac Applications and Mac App Store 1 Jun 9, 2013 03:28 PM
Basic? FCP X question DaveNinja Digital Video 2 Nov 6, 2012 04:40 PM
Basic question about iCloud Loa iCloud and Apple Services 11 Jun 12, 2012 03:46 PM
Basic question on syncing. classie787 iPod touch 2 Jun 7, 2012 06:33 AM

Forum Jump

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

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

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