Hi
I'm doing some Objective-C exercises in TextMate. Up until now, I've put everything (interface, implementation and main) into one file and hit cmd-R (presumably activating the C bundle's Run command) to see the output. Now I want to use separate files, with the #import command. Unfortunately, when I try this, I get an error about how my class can't be found. Here's the code :
#import "Rectangle.h"
int main (int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Rectangle *rectangle = [[Rectangle alloc] init];
[pool drain]; return 0; }
And the error it gives:
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 understand that I can do this in Xcode, or using the terminal, but since I'm making quick changes, I want to see the results quickly. Making a change and hitting cmd-R let me do this easily.
I looked at the Xcode bundle, which also has a "Run" command, but it seems to require an Xcode project to work.
Is there a way to get my files to link automatically before running? Thanks.
Nevan
On 19 Oct 2011, at 13:34, Nevan King wrote:
[…] I want to use separate files […] the error it gives:
When you use multiple files you effectively need a build system.
A build system compiles each file individually into an object file and then link the object files together into an executable.
Since TextMate doesn’t know what objects your executable may need (based on the current file) it can’t easily have ⌘R do all this for you.
It’s also common to include other steps as part of the building process, like copying resources, preprocessing files, etc.
[…] I looked at the Xcode bundle, which also has a "Run" command, but it seems to require an Xcode project to work.
The Xcode bundle is simply a frontend for running “xcodebuild”, which uses Xcode’s proprietary build system.
Is there a way to get my files to link automatically before running? Thanks.
Well, since ⌘R allows you to set additional options via the OBJC_FLAGS variable, it is technically possible to simply add all your files via that variable. When gcc/clang is given multiple files, it will build and link them all.
Another approach is creating a simple Makefile and use ⌘B from the Make bundle. But this require you to learn about make.