我有这些文件:
项目.m
#import "Fraction.h"
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Fraction *fraction = [[Fraction alloc] init];
[fraction setNumerator: 2];
[fraction setDenominator: 3];
[fraction print];
NSLog(@"%g", [fraction value]);
[fraction release];
[pool drain];
return 0;
}
分数.m
#import "Fraction.h"
@implementation Fraction
-(void) setNumerator: (int) n {
numerator = n;
}
-(void) setDenominator: (int) d {
denominator = d;
}
-(void) print {
NSLog(@"%i/%i\n", numerator, denominator);
}
-(double) value {
return (double) numerator / denominator;
}
@end
分数.h
#import <Foundation/Foundation.h>
@interface Fraction: NSObject {
int numerator, denominator;
}
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(void) print;
-(double) value;
@end
像这样安排在一个文件中:
Objective-C
|_Fraction.h
|_Fraction.m
|_Project.m
但是,当我运行这个(我正在使用GNUstep
)时,我收到了这个错误:
undefined reference to '__objc_class_name_Fraction'