• 0

[Objective C] Help needed with the following compilation errors


Question

I tried to compile the following code

#import <stdio.h>
#import <objc/Object.h>

//----------interface--------------

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

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;

@end

//-----------implementation--------

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

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

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

//-------------program-------------

int main (int argc, char *argv[])
{
	Fraction *myFraction;

	myFraction = [Fraction alloc];
	myFraction = [myFraction init];

	[myFraction setNumerator: 1];
	[myFraction setDenominator: 3];

	printf ("The value of my fraction is: ");
	[myFraction print];
	printf ("\n");
	[myFraction free];

	return 0;
]

and i got the following set of compilation error

[rustix@localhost Objective-C]$ gcc *.m
fraction.m: In function ‘main’:
fraction.m:55: error: expected statement before ‘]’ token
fraction.m:55: error: expected declaration or statement at end of input

anyone could help correct my program?

Edited by rustix

3 answers to this question

Recommended Posts

  • 0

now i get another problem after fixing the abov e mistake

[rustix@localhost Objective-C]$ gcc *.m
/tmp/ccwebvTv.o: In function `main':
hello.m:(.text+0x0): multiple definition of `main'
/tmp/cceeY7V1.o:fraction.m:(.text+0x30): first defined here
/usr/bin/ld: Warning: size of symbol `main' changed from 306 in /tmp/cceeY7V1.o to 71 in /tmp/ccwebvTv.o
/tmp/cceeY7V1.o: In function `main':
fraction.m:(.text+0x4a): undefined reference to `objc_get_class'
fraction.m:(.text+0x5d): undefined reference to `objc_msg_lookup'
fraction.m:(.text+0x84): undefined reference to `objc_msg_lookup'
fraction.m:(.text+0xab): undefined reference to `objc_msg_lookup'
fraction.m:(.text+0xd7): undefined reference to `objc_msg_lookup'
fraction.m:(.text+0x10f): undefined reference to `objc_msg_lookup'
/tmp/cceeY7V1.o:fraction.m:(.text+0x13f): more undefined references to `objc_msg_lookup' follow
/tmp/cceeY7V1.o: In function `__objc_gnu_init':
fraction.m:(.text+0x170): undefined reference to `__objc_exec_class'
/tmp/cceeY7V1.o:(.data+0x1b8): undefined reference to `__objc_class_name_Object'
collect2: ld returned 1 exit status

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Anyway to download these versions without being on the Experimental builds?
    • Nothing is stopping you from continuing with your testing cadence. If updates are released every 2 weeks instead of 4, and you test once every 4 weeks, the exact same amount of patches will still be available for you in those 4 weeks. For example: Before 4th week - patch 1, 2, 3, 4 After 2nd week - patch 1 and 2 4th week - patch 3 and 4 Still the same amount after 4.
    • Everyone else has said it. I'm gonna say it - you don't know what you're talking about. I do. I have two laptops. One work, one personal. I have access to two more laptops - both personal. At home I manually update my personal laptop when I see on Neowin that there is an update - I carry on and only apply the updates when I am ready. My work one only updates when my workplace decides to send it - I carry on and only apply the updates (when they actually arrive, which is usually days after the release) when I switch off the laptop at the end of the day as usual. The two other personal laptops only get updated when I get to it which is rarely - the people who own them carry on using them until I get to it and update them. All of the browsers on all laptops are configured to restore the tabs when launched. Google and Microsoft have changed from 6 weeks to 4, and it looks like it's going to move to 2. None of these changes affect how any of these browsers on the laptops are used. Not one jot. My advice to you is stop panicking whenever you see an update. Just carry on with what you're doing. This even benefits you in a way - from your comment you sound like you don't like the changes or the frivolous new features - great - then carry on as before!
    • AMAZON needs to take total accountability for this.
    • Server Summit had a heap of announcements, ADCS changes are baller.
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      509
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      80
  • Tell a friend

    Love Neowin? Tell a friend!