-1

これはCircle.h次のとおりです。

#import <Foundation/Foundation.h>

typedef enum{
    KCircle,
    KRectangle
}ShapeType;

typedef enum{
    KRedColor,
    KGreenColor,
    KBlueColor
}ShapeColor;

typedef struct{
    int x, y, width, height;
}ShapeRect;


typedef struct{
    ShapeType type;
    ShapeColor fillColor;
    ShapeRect bounds;
}Shape;

@interface Circle : NSObject{
    ShapeColor mColor;
    ShapeRect mBound;
}

-(void) setBound: (ShapeRect) bound;
-(void) setFillColor: (ShapeColor) color;
-(void) draw;
@end

これはCircle.m

#import "Circle.h"

@implementation Circle

-(void) setBound:(ShapeRect)bound{
    mBound = bound;
}

-(void)setFillColor:(ShapeColor)color{
    mColor = color;
}

-(NSString*) colorName: (ShapeColor)color{
    switch (color) {
        case KGreenColor:
            return @"Green";
            break;
        case KRedColor:
            return @"Red";
            break;
        case KBlueColor:
            return @"Blue";
            break;
        default:
            break;
    }
}

-(void) draw
{
    NSLog(@"drawing a circle (%d %d %d %d) in %@",
          mBound.x, mBound.y, mBound.width, mBound.height, colorName(mColor));
}

@end

ファイルをコンパイルすると、次のエラーが発生します。

Undefined symbols for architecture x86_64:
"_colorName", referenced from:
  -[Circle draw] in Circle.o
 (maybe you meant: _colorName1)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
4

1 に答える 1