Note that there are some explanatory texts on larger screens.

plurals
  1. POCompilation Errors in running objective c code in ubuntu 12.10
    primarykey
    data
    text
    <p>I'm trying to run the following code: </p> <pre><code>#import &lt;stdio.h&gt; #import &lt;Foundation/NSObject.h&gt; //--------@interface section-------- @interface Fraction: NSObject { int numerator; int denominator; } -(void) setNumerator: (int) n; -(void) setDenominator: (int) d; -(void) print; @end //-------@implementation section------- @implementation Fraction; //getters -(int) numerator { return numerator; } -(int) denominator { return denominator; } //setters -(void) setNumerator: (int) num { numerator = num; } -(void) setDenominator: (int) denom { denominator = denom; } //other -(void) print { printf("The value of the fraction is %i/%i\n", numerator, denominator); } @end //---------program section--------- int main(void) { Fraction *myFract; myFract = [Fraction new]; [myFract setNumerator: 1]; [myFract setDenominator: 3]; printf("The numerator is %i, and the denominator is %i\n", [myFract numerator], [myFract denominator]); [myFract print]; [myFract free]; return 0; } </code></pre> <p>when I compile it</p> <pre><code>$gcc -framework Foundation p10.m </code></pre> <p>I got ff. errors:</p> <pre><code>Program19_2.m: In function ‘main’: Program19_2.m:55:2: warning: ‘Fraction’ may not respond to ‘+new’ [enabled by default] Program19_2.m:55:2: warning: (Messages without a matching method signature [enabled by default] Program19_2.m:55:2: warning: will be assumed to return ‘id’ and accept [enabled by default] Program19_2.m:55:2: warning: ‘...’ as arguments.) [enabled by default] Program19_2.m:64:2: warning: ‘Fraction’ may not respond to ‘-free’ [enabled by default] /tmp/ccVRbEBu.o: In function `main': Program19_2.m:(.text+0x6d): undefined reference to `objc_get_class' Program19_2.m:(.text+0x7f): undefined reference to `objc_msg_lookup' Program19_2.m:(.text+0xa4): undefined reference to `objc_msg_lookup' Program19_2.m:(.text+0xcd): undefined reference to `objc_msg_lookup' Program19_2.m:(.text+0xf6): undefined reference to `objc_msg_lookup' Program19_2.m:(.text+0x119): undefined reference to `objc_msg_lookup' /tmp/ccVRbEBu.o:Program19_2.m:(.text+0x14e): more undefined references to `objc_msg_lookup' follow /tmp/ccVRbEBu.o: In function `__objc_gnu_init': Program19_2.m:(.text+0x19a): undefined reference to `__objc_exec_class' /tmp/ccVRbEBu.o:(.data+0x148): undefined reference to `__objc_class_name_Object' collect2: error: ld returned 1 exit status </code></pre> <p>I just copied the code from a textbook. Change the libraries I import because they are (Object.h) now deprecated. I wonder why it doesn't run. Is there something wrong with the way I compile the program?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload