Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 590
OTZ Avatar asked Sep 22 '13 11:09

OTZ


2 Answers

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! :)

like image 195
OTZ Avatar answered Oct 23 '22 01:10

OTZ


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.

like image 32
Michael Avatar answered Oct 23 '22 01:10

Michael