tags:

views:

95

answers:

3

I'm having problems compiling the following program. I'm using "gcc -framework Foundation inherit8.1m" and get the following errors. What am I doing wrong? Thanks.

ld warning: in inherit8.1m, file is not of required architecture Undefined symbols: "_main", referenced from: start in crt1.10.5.o ld: symbol(s) 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;
}
+4  A: 

Try renaming your source file to something that ends in just .m. Your file has an extension of .1m which appears to confuse the compiler.

Paul M
Whoops, I meant to name the file "inherit8.1.m". Thanks.
Stu
+1  A: 

You've misnamed your file. It should be inherit8.m, not inherit8.1m.

Rob Napier
+1  A: 

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
stefanB