0

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;
}
2
  • Even though you're question has been aswered, seeing this question is funny. I'm currently reading through that same segment of Kochan's book. Great book huh? Why don't you just use xcode? Commented May 18, 2009 at 13:20
  • I was in a hurry to learn Objective-C, and had access to a Mac shell. (but no access to a physical machine) XCode is much more convenient. Commented May 28, 2009 at 20:47

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Whoops, I meant to name the file "inherit8.1.m". Thanks.
1

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.