Question

I'm using TextMate to do some Objective-C exercises. When everything is in one file, it works fine, but as soon as I want to work with multiple files it gives an error. For example, I have a separate Rectangle.h file to be imported:

#import "Rectangle.h"

int main (int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    Rectangle *rectangle = [[Rectangle alloc] init];

    [pool drain];
    return 0;
}

Running gives this error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Rectangle", referenced from:
      objc-class-ref in ccccStDD.o
ld: symbol(s) not found for architecture x86_64

I'm using the C bundle's "Run" command. Using the Xcode bundle's "Build & Run" command gives me a different error.

How can I make TextMate import my Rectangle.h file and run?

Was it helpful?

Solution

It's not a compiler error, but a linker error. Your import should be fine, as long as it's in the same directory as your main file.

I guess you should also have a Rectangle.m file. You need to compile both files (Rectangle.m and your main file) as object files (with the -c argument), and then link them together to produce an executable.

Or simply compile both files together:

gcc -Wall -framework Foundation -o test test.m Rectangle.m

Note that if your header files are in a separate directory, you can specify it to GCC using the -i or -I arguments.

EDIT:

I've just seen a mention of Xcode. Are you using Xcode or TextMate?

If you compile using Xcode, and get the error, it's likely that your Rectangle.m file is not part of your main Xcode target.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top