ObjC - ZeroLink Problems *Again*

Member
Posts: 21
Joined: 2009.05
Post: #1
Greetings all,
I just got my ObjC book and started playing with the first examples in the book. So far it's very intriguing and I want to play around with objects, classes, methods, etc. more. However, when I run my program (posted a bit below), I get the following error: [ ZeroLink: unknown symbol '_objc_getClass' ]. This is similar to the problem I had with the ncurses.h, where I had to manually tell xcode to link to the ncurses library (BTW, this problem was never solved... I just stopped pestering you all with it... [Link] ).

This is the code I am running:

Code:
#include <stdio.h>
#include <objc/Object.h>

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

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

@end

@implementation Fraction

    -(void) print
    {
        printf( " %d/%d ", numerator, denominator );
    }
    
    -(void) setNumerator: (int) n;
    {
        numerator = n;
    }
    
    -(void) setDenominator: (int) d;
    {
        denominator = d;
    }

@end
    

int main(void)
{
    Fraction *myFraction = [[ Fraction alloc ] init ];
    
    [ myFraction setNumerator: 5 ];
    [ myFraction setDenominator: 1 ];
    [ myFraction print ];
    [ myFraction free ];

    return 0;
}

I did a few searches on Google and could not find anything. Why do I seem to run into all these weird problems? I am following the tutorials by the letter. *sigh*

If you know what I can do to fix this problem, please let me know. Smile Thank you for your time and help as always, and sorry to frequently bother you with newbish questions. >< Have a good one!

~Achi
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Looks like you haven't included -lobjc in your linker flags. It compiles and runs for me with `gcc -lobjc Acithyn.m`.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.05
Post: #3
The problem is, I can compile curses.h and objc/Object.h using terminal, though when it comes to Xcode, everything I do won't work. I've tried added the tags, adding libraries, etc. In the end, I guess I just don't know where to add them.

I go to the project [PlayTest], go to [Get Info], go to the [Build] tab, then press [Edit] on the [Other Linker Flags]. From there, I add -lobjc, so the list looks like:

$(inherited)
-lobjc

Is this wrong? Thanks for your time. Smile

~Achi
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #4
It might be easiest to just add the Cocoa framework to your project.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.05
Post: #5
Hey guys,
Alright, I added the cocoa.framework and, it works! Smile You won't believe how excited I got when I compiled my program and the actual results were displayed. Now, do you 'have' to include the framework, or can you add the linker flag? If you can add the linker flag, why does it not work? Is the following incorrect?

Quote:I go to the project [PlayTest], go to [Get Info], go to the [Build] tab, then press [Edit] on the [Other Linker Flags]. From there, I add -lobjc, so the list looks like:

$(inherited)
-lobjc
Well, at least I can now start programming again. Thank you for your help! Grin

~Achi
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #6
I have no idea why the linker flag won't work, but ff you don't want to add the Cocoa framework, you can simply add libobjc to your project, too (it's in /user/bin).
Quote this message in a reply
Member
Posts: 21
Joined: 2009.05
Post: #7
Hmmm, I tried that though it didn't seem to work. Just to make sure, I added libobjc.A.dylib, is that correct? When I looked in the usr/bin, there were no file for libobjc. I had to go to Developer > SDKs > MacOSX10.4u.sdk > usr > lib > libobjc.dylib || libobjc.A.dylib.

I think I will just use the cocoa framework. I'm only learning ObjC right now in preparation for my Cocoa book. I wonder if some of these problems have to do with a problem with my mac? Anyway, I'll be getting a new iMac here soon enough to test that idea. Rasp

Thanks again for your help. Smile

~Achi
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Cochrane should have said /usr/lib
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  newbie c to objc... best practices arcnon 1 2,132 Dec 10, 2005 12:38 PM
Last Post: zKing