Include Error

Discussion in 'Mac Programming' started by Thethuthinang, Dec 16, 2011.

  1. macrumors member

    Joined:
    Jan 3, 2011
    #1
    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);
    
     
  2. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3
    (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
     
  4. Thethuthinang, Dec 16, 2011
    Last edited: Jan 28, 2012

    thread starter macrumors member

    Joined:
    Jan 3, 2011
    #4
    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.
     
  5. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #5
    I'm assuming you've got the problem taken care of.
     

Share This Page