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

Thethuthinang

macrumors member
Original poster
Jan 3, 2011
39
0
My project uses a lot of geometry and so I wrote a set of functions that operate on NSPoints (translate, rotate, etc.). I put these in THPointOperations.c and THPointOperations.h and these files are located in "other sources" within Xcode. Since I must tell the compiler what an NSPoint is, I use "#import <Cocoa/Cocoa.h>" in the header. This produces hundreds of errors, all showing at the beginning of THPointOperations.c, but located in the cocoa framework. I know this is just a simple misunderstanding of the basics, but I don't know where to look for the answer. Any suggestions? Here is THPointOperations.h:
Code:
#import <Cocoa/Cocoa.h>

void translate(NSPoint *p, NSPoint q);
NSPoint pointByAdding(NSPoint p, NSPoint q);
NSPoint pointBySubtracting(NSPoint p, NSPoint q);
void scaleBy(NSPoint *p, float t);
void rotate(NSPoint *p, float cosAngle, float sinAngle);
void reflectX(NSPoint *p);
void reflectY(NSPoint *p);
float distance(NSPoint p, NSPoint q);
 
My project uses a lot of geometry and so I wrote a set of functions that operate on NSPoints (translate, rotate, etc.). I put these in THPointOperations.c and THPointOperations.h and these files are located in "other sources" within Xcode. Since I must tell the compiler what an NSPoint is, I use "#import <Cocoa/Cocoa.h>" in the header. This produces hundreds of errors, all showing at the beginning of THPointOperations.c, but located in the cocoa framework. I know this is just a simple misunderstanding of the basics, but I don't know where to look for the answer. Any suggestions? Here is THPointOperations.h:
Code:
#import <Cocoa/Cocoa.h>

void translate(NSPoint *p, NSPoint q);
NSPoint pointByAdding(NSPoint p, NSPoint q);
NSPoint pointBySubtracting(NSPoint p, NSPoint q);
void scaleBy(NSPoint *p, float t);
void rotate(NSPoint *p, float cosAngle, float sinAngle);
void reflectX(NSPoint *p);
void reflectY(NSPoint *p);
float distance(NSPoint p, NSPoint q);
(Red hilite added)

Cocoa is Objective-C, so Cocoa.h is necessarily Objective-C. If your file is named something.c, then the default language it will be compiled as is C. To be compiled by default as Objective-C, suffix it with .m, not .c.

NSPoint is a typedef, which is valid in both C and Objective-C. So from a technical standpoint, you don't need Objective-C to use the NSPoint typedef. But from a practical one, you don't include the foundation types header (which defines NSPoint) except by including an Objective-C header.

http://developer.apple.com/library/...Foundation_DataTypes/Reference/reference.html
 
Here is the output from Build Results:

Code:
> In include file from /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:
     > In file included from /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:

           X error: syntax error before '@' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token
           X error: syntax error before '*' token

Most of the errors are similar, but occur in other included files. Later there is the error:

Code:
X 'CGAffineTransform' undeclared (first use in this function)

Of course, it is defined. I just somehow precluded the definition.

----------

Thanks chown33. The .c suffix instead of .m was indeed the problem.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.