Hello,
I am following a guide found on the internet and I am unable to compile it. Following are me 3 source code files:
Fraction.h
Fraction.m
main.m
Compiling:
Error produced:
Any ideas? Please?
Regards,
Jeff
I am following a guide found on the internet and I am unable to compile it. Following are me 3 source code files:
Fraction.h
Code:
#import <Foundation/NSObject.h>
@interface Fraction : NSObject {
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(int) numerator;
-(int) denominator;
@end
Fraction.m
Code:
#import "Fraction.h"
#import <stdio.h>
@implementation Fraction
-(void) print {
printf("%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n {
numerator = n;
}
-(void) setDenominator: (int) d {
denominator = d;
}
-(int) denominator {
return denominator;
}
-(int) numerator {
return numerator;
}
@end
main.m
Code:
#import <stdio.h>
#import "Fraction.h"
int main( int argc, const char *argv[] ) {
// create a new instance
Fraction *frac = [[Fraction alloc] init];
// set the values
[frac setNumerator: 1];
[frac setDenominator: 3];
// print it
printf( "The fraction is: " );
[frac print];
printf( "\n" );
// free memory
[frac release];
return 0;
}
Compiling:
Code:
gcc Fraction.m main.m -o myapp
Error produced:
Code:
/usr/bin/ld: Undefined symbols:
.objc_class_name_NSObject
_objc_msgSend
collect2: ld returned 1 exit status
Any ideas? Please?
Regards,
Jeff