Compiling an Objective-C Program
I am having trouble compiling the following program. I am using "gcc -framework Foundation inherit8.1m" and am getting the following errors. What am I doing wrong? Thanks.
ld warning: in inherit8.1m, not required architecture file Undefined symbols: "_main" referenced by: start at crt1.10.5.o ld: symbol not found collect2: ld returned 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;
}
0
a source to share
3 answers
I found it easier to use GNUmakefile on Linux (not sure if this is your case). I have a command line tool LogTest
compiled from source.m
:
> cat source.m
#import <Foundation/Foundation.h>
int main(void)
{
NSLog(@"Executing");
return 0;
}
> cat GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = LogTest
LogTest_OBJC_FILES = source.m
include $(GNUSTEP_MAKEFILES)/tool.make
> make
Making all for tool LogTest...
Compiling file source.m ...
Linking tool LogTest ...
> ./obj/LogTest
2009-05-17 20:05:36.032 LogTest[9850] Executing
+1
a source to share