Find the answer to your Linux question:
Results 1 to 2 of 2
ok, so i am somewhat new to linux and have VERY basic knowledge of programming. I am trying to learn Objective-C and here is this sample program using classes. Code: ...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Location
    Syracuse, New York
    Posts
    53

    What is this error when I try to compile a simple C program in gcc?

    ok, so i am somewhat new to linux and have VERY basic knowledge of programming. I am trying to learn Objective-C and here is this sample program using classes.
    Code:
    // Program to work with fractions - class version
    #import <stdio.h>
    #import <objc/Object.h>
    
    //--------------@interface section-------------
    
    @interface Fraction: Object
    {
    	int numerator;
    	int denominator;
    }
    
    -(void) print;
    -(void) setNumerator: (int) n;
    -(void) setDenominator: (int) d;
    
    @end
    
    //-----------@implimentation section--------------------
    
    @implementation Fraction;
    -(void) print
    {
    	printf (" %i/%i ", numerator, denominator);
    }
    
    -(void) setNumerator: (int) n
    {
    	numerator = n;
    }
    
    -(void) setDenominator: (int) d
    {
    	denominator = d;
    }
    
    @end
    
    //-------------program section----------------
    
    int main (int argc, char *argv[])
    {
    	Fraction *myFraction;
    
    // Create an instance of a Fraction
    
    	myFraction = [Fraction alloc];
    	myFraction = [myFraction init];
    
    // Set Fraction to 1/3
    	[myFraction setNumerator: 1];
    	[myFraction setDenominator: 3];
    
    // Display the fraction using the print method
    
    	printf ("The value of myFraction is:");
    	[myFraction print];
    	printf ("\n");
    	[myFraction free];
    
    	return 0;
    }

    When I try and compile it I get this:
    Code:
    [mstshtml@localhost prog3]$ gcc main.m -o prog3-2
    /tmp/ccu7A1rE.o: In function `main':
    main.m:(.text+0x7b): undefined reference to `objc_get_class'
    main.m:(.text+0x8b): undefined reference to `objc_msg_lookup'
    main.m:(.text+0xad): undefined reference to `objc_msg_lookup'
    main.m:(.text+0xd5): undefined reference to `objc_msg_lookup'
    main.m:(.text+0xfe): undefined reference to `objc_msg_lookup'
    main.m:(.text+0x136): undefined reference to `objc_msg_lookup'
    /tmp/ccu7A1rE.o:main.m:(.text+0x164): more undefined references to `objc_msg_lookup' follow
    /tmp/ccu7A1rE.o: In function `__objc_gnu_init':
    main.m:(.text+0x18e): undefined reference to `__objc_exec_class'
    /tmp/ccu7A1rE.o:(.data+0x2e8): undefined reference to `__objc_class_name_Object'
    collect2: ld returned 1 exit status
    can someone help me with whats going on with this error?
    thank
    -steve

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    I have exactly zero experience with objetive C, but, it's a linker error. You probably have to include the path to the compiled object library. I don't know what that is called. The command would be something like:

    Code:
    gcc main.m -o prog3-2 -L/path/to/Object/lib

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...