Adam
Adam

Reputation: 9049

I'm getting Failed with exit code 1 error in xcode

This is my first ever attempt at a Objective-c cocoa program, so I have no clue why it is giving me that error. I really don't understand the Build Result page either.

myClass.h

#import <Cocoa/Cocoa.h>


@interface myClass : NSObject {
    int a;
    int b;
}

-(void) setvara:(int)x;
-(void) setvarb:(int)y;
-(int) add;

@end

myClass.m

#import "myClass.h"


@implementation myClass

-(void)setvara:(int)x{
    a=x;    
}

-(void)setvarb:(int)y{
    b=y;    
}

-(int)add{
    return a+b; 
}
@end

main.m

#import <Cocoa/Cocoa.h>
#import <stdio.h>
#import "myClass.m"

int main(int argc, const char* argv[])
{
    myClass* class = [[myClass alloc]init];

    [class setvara:5];
    [class setvarb:6];

    printf("The sum: %d", [class add]);

    [class release];

}

Upvotes: 1

Views: 2148

Answers (1)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

In your main.m, you want to import myClass.h, not myClass.m

The header file has the declarations you need. If you import the implementation, you are implementing those methods twice, hence the duplicate symbols.

Another tip as you learn, when you say [[myClass alloc] init], what you get back is a pointer to an object, not a class. So you should call it an object just so that concept is reinforced for you. Getting the difference straight now will help you greatly as you get deeper into this.

(there are a couple of naming convention issues here also, btw)

Upvotes: 4

Related Questions