0

I am trying to compile the following example from http://www.otierney.net/objective-c.html. It consists of three files:

Fraction.h

#import <Foundation/NSObject.h>

@interface Fraction: NSObject {
        int numerator;
        int denominator;
}

-(void) print;
-(void) setNumerator;
-(void) setDenominator;
-(int) numerator;
-(int) denominator;
@end

Fraction.m

#import <stdio.h>

@implementation Fraction
-(void) print {
        printf("%i/%i", numerator, denominator);
}

-(void) setNumerator: (int) n {
        numerator = n;
}

-(void) setDenominator: (int) d {
        denominator = d;
}

-(int) denominator {
        return denominator;
}

-(int) numerator {
        return numerator;
}
@end

main.m

#import <stdio.h>
#import "Fraction.h"

int
main(int argc, char **argv)
{
    //Create a new instance
    Fraction *frac = [[Fraction alloc] init];

    //set the values
    [frac setNumerator: 1];
    [frac setDenominator: 3];

    //print it
    printf("The fraction is: ");
    [frac print];
    printf("\n");

    //Frac memory
    [frac release];
    return 0;
}

Using to following to compile

$ gcc `gnustep-config --objc-flags` -lobjc -lgnustep-base main.m -o main

This produces a main.d file, that is just ascii

$ cat main.d

main: main.m Fraction.h /usr/include/GNUstep/Foundation/NSObject.h \
 /usr/include/GNUstep/Foundation/NSObjCRuntime.h \
 /usr/include/GNUstep/GNUstepBase/GSVersionMacros.h \
 /usr/include/GNUstep/GNUstepBase/GSConfig.h \
 /usr/include/GNUstep/GNUstepBase/preface.h \
 /usr/include/GNUstep/GNUstepBase/GSObjCRuntime.h \
 /usr/include/GNUstep/ObjectiveC2/runtime.h \
 /usr/include/GNUstep/ObjectiveC2/Availability.h \
 /usr/include/GNUstep/Foundation/NSZone.h \
 /usr/include/GNUstep/GNUstepBase/GNUstep.h \
 /usr/include/GNUstep/Foundation/NSDate.h \
 /usr/include/GNUstep/GNUstepBase/NSObject+GNUstepBase.h

Fraction.h:

/usr/include/GNUstep/Foundation/NSObject.h:

/usr/include/GNUstep/Foundation/NSObjCRuntime.h:

/usr/include/GNUstep/GNUstepBase/GSVersionMacros.h:

/usr/include/GNUstep/GNUstepBase/GSConfig.h:

/usr/include/GNUstep/GNUstepBase/preface.h:

/usr/include/GNUstep/GNUstepBase/GSObjCRuntime.h:

/usr/include/GNUstep/ObjectiveC2/runtime.h:

/usr/include/GNUstep/ObjectiveC2/Availability.h:

/usr/include/GNUstep/Foundation/NSZone.h:

/usr/include/GNUstep/GNUstepBase/GNUstep.h:

/usr/include/GNUstep/Foundation/NSDate.h:

/usr/include/GNUstep/GNUstepBase/NSObject+GNUstepBase.h:
1
  • Please reformat. There are instructions available by clicking the big orange ? just above the edit window. Commented Oct 15, 2010 at 18:21

1 Answer 1

1

I have an answer for you. Here is what you need:
1. Setup GNUstep just like on this site: http://camelek.wikidot.com/wprowadzenie-do-objective-c
2. Create GNUmakefile with that content:

include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Fraction
$(TOOL_NAME)_OBJC_FILES = main.m Fraction.m
include $(GNUSTEP_MAKEFILES)/tool.make

Here is how your compilation will look like, and how works your new program:

camelek@debian:~/.../Fraction$ gs_make

This is gnustep-make 2.6.2. Type 'make print-gnustep-make-help' for help.
Making all for tool Fraction...
Compiling file main.m ...
Compiling file Fraction.m ...
Linking tool Fraction ...
camelek@debian:~/.../Fraction$ file ./obj/Fraction
./obj/Fraction: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26,  BuildID[sha1]=0xd25682721d14fd4e0fb48bb999797da28d4f8940, not stripped
camelek@debian:~/.../Fraction$ ./obj/Fraction
The fraction is: 1/3
camelek@debian:~/.../Fraction$ 

I am using Debian Wheezy 7.1

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

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.