PDA

View Full Version : Include Error




Thethuthinang
Dec 16, 2011, 12:32 PM
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:

#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);



lloyddean
Dec 16, 2011, 01:09 PM
Post the first 10 or so errors.

chown33
Dec 16, 2011, 01:38 PM
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:

#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/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html

Thethuthinang
Dec 16, 2011, 01:49 PM
Here is the output from Build Results:

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


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.

lloyddean
Dec 16, 2011, 04:11 PM
I'm assuming you've got the problem taken care of.