james-collinss-macbook-prorog9 jamescollins$ gcc prog9.2.m -o prog9.2 -l objc
Undefined symbols:
".objc_class_name_Complex", referenced from:
literal-pointer@__OBJC@__cls_refs@Complex in cciaLwic.o
".objc_class_name_Fraction", referenced from:
literal-pointer@__OBJC@__cls_refs@Fraction in cciaLwic.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
got this error message when i tried to run a program from a book.
here is my test file which i called prog9.2.m
Undefined symbols:
".objc_class_name_Complex", referenced from:
literal-pointer@__OBJC@__cls_refs@Complex in cciaLwic.o
".objc_class_name_Fraction", referenced from:
literal-pointer@__OBJC@__cls_refs@Fraction in cciaLwic.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
got this error message when i tried to run a program from a book.
here is my test file which i called prog9.2.m
Code:
//illustrate Dynamic Typing and Binding
#import "Fraction.h"
#import "Complex.h"
int main (int argc, char *argv[])
{
id dataValue;
Fraction *f1 = [[Fraction alloc] init];
Complex *c1 = [[Complex alloc] init];
[f1 setTo: 2 over: 5];
[c1 setReal: 10.0 andImaginary: 2.5];
// first dataValue gets a fraction
dataValue = f1;
[dataValue print];
printf ("\n");
//now dataValue gets a complex number
dataValue = c1;
[dataValue print];
printf ("\n");
[c1 free];
[f1 free];
[dataValue free];
return 0;
}
[code]
i think the problem is in Complex.h and Fraction.h so i will include those two files.
first Fraction.h
[code]
#import <objc/Object.h>
#import <stdio.h>
// define the fraction class
@interface Fraction : Object
{
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(void) setTo: (int) n over: (int) d;
-(void) reduce;
-(int) numerator;
-(int) denominator;
-(double) convertToNum;
@end
[code]
and then Complex.h
[code]
//Interface file for Complex class
#import <objc/Object.h>
@interface Complex: Object
{
double real;
double imaginary;
double compResult;
}
-(void) print;
-(void) setReal: (double) a;
-(void) setImaginary: (double) b;
-(void) setReal: (double) a andImaginary: (double) b;
-(double) real;
-(double) imaginary;
-(double) compResult;
-(Complex *) add: (Complex *) f;
@end
[code]
any help would be appreciated.