John Smith
John Smith

Reputation: 12807

NSStringFromPoint disappears under Objective-C++

The function NSStringFromPoint disappears when I compile my code using objective-C++, but it's fine under objective-C.

How can I make objective-C++ see that function?

If I compile under Objective-C++ it says:

error: 'NSStringFromPoint' was not declared in this scope
error: 'NSStringFromRect' was not declared in this scope
error: 'NSEqualSizes' was not declared in this scope

Upvotes: 0

Views: 712

Answers (2)

Alex
Alex

Reputation: 26859

Someone can correct me if I'm wrong, but if you're linking against the iPhone SDK, there is no NSPoint or NSStringFromPoint. UIKit uses the Core Graphics structs CGPoint, CGSize and CGRect. The equivalent function would be NSStringFromCGPoint.

The Simulator libraries do not quite match up with the iPhone libraries -- I'm fairly certain applications compiled for the simulator link against the Mac's own Foundation.framework. For example, I wasted a lot of time in the pre-2.0 days thinking that NSXMLDocument was available on iPhone because it compiled and ran in the simulator.

Upvotes: 3

dreamlax
dreamlax

Reputation: 95355

I compiled this simple application:

#include <Cocoa/Cocoa.h>
int main (void)
{
    NSLog (@"%@", NSStringFromPoint(NSMakePoint(10, 10));
    return 0;
}

Using this command line:

gcc -x objective-c++ test.mm -framework Cocoa -lstdc++

And I got this output (ignoring the error about no autorelease pool in place):

2010-05-12 12:41:33.946 a.out[290:10b] {10, 10}

Make sure you're including the right headers, at the very least, make sure you're importing <Foundation/Foundation.h>. An explicit #import <Foundation/Foundation.h> will do no harm if it has already been included.

Upvotes: 1

Related Questions