Ich habe Probleme beim Kompilieren des folgenden Programms. Ich verwende "gcc -framework Foundation inherit8.1m" und erhalte die folgenden Fehler. Was mache ich falsch? Vielen Dank.Kompilieren eines Objective-C-Programms
ld Warnung: in inherit8.1m, Datei ist nicht erforderlich Architektur undefiniert Symbole: "_main", verwiesen von: Start in crt1.10.5.o ld: Symbol (e) nicht gefunden collect2: ld ergab 1 Exit-Status
// Simple example to illustrate inheritance
#import <Foundation/Foundation.h>
// ClassA declaration and definition
@interface ClassA: NSObject
{
int x;
}
-(void) initVar;
@end
@implementation ClassA
-(void) initVar
{
x = 100;
}
@end
// Class B declaration and definition
@interface ClassB : ClassA
-(void) printVar;
@end
@implementation ClassB
-(void) printVar
{
NSLog (@"x = %i", x);
}
@end
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
ClassB *b = [[ClassB alloc] init];
[b initVar]; // will use inherited method
[b printVar]; // reveal value of x;
[b release];
[pool drain];
return 0;
}
Auch wenn du bist Frage aswered worden ist, diese Frage zu sehen komisch. Ich lese gerade das gleiche Segment von Kochans Buch durch. Tolles Buch, nicht wahr? Warum benutzt du nicht einfach xcode? –
Ich hatte es eilig, Objective-C zu lernen und hatte Zugriff auf eine Mac-Shell. (aber kein Zugang zu einer physischen Maschine) XCode ist viel bequemer. – Stu