OTZ
OTZ

Reputation: 3073

Compiling .m objective-C file from command-line

In the old days I could have compiled objective-c .m files with

$ gcc -fobjc-gc-only -framework Foundation sample.m
$ ./a.out

But now it doesn't work because there is a high chance the program has

@autoreleasepool { ... }

clause. How do I compile an objective-C on command-line now?

Upvotes: 5

Views: 2831

Answers (2)

Michael
Michael

Reputation: 1213

xcodebuild is what the XCode IDE uses under the hood to build you app, and what you use in things like CI servers to kick off a build from the command line. It uses your .xcproj or .xcworkspace files to work out what to build, so that may still be too high level for you.

In which case, under xcodebuild is clang and llvm. Clang replaced gcc, and is somewhat backwardly compatible, so that would be where you would want to start I would think.

Upvotes: 1

OTZ
OTZ

Reputation: 3073

So I just tried out clang and it worked out beautifully.

$ clang -fobjc-gc-only -framework Foundation  sample.m
$ ./a.out
2013-09-22 20:17:57.150 a.out[19858:903] Hello world.    

Case closed! :)

Upvotes: 9

Related Questions