5

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?

1
  • 1
    Perhaps the easiest way to get the exact info you want is to build it within Xcode, then go look at the build output. Commented Sep 22, 2013 at 11:14

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

for arc environment use -fobjc-arc
1

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.

3 Comments

Yep, clang worked. I suppose xcodebuild is a thin layer above clang and apple llvm. I'd love to know how to compile any xcode project from command-line.
Pretty much. xcodebuild is like make and clang is gcc so start playing with xcodebuild to compile any xcode project. It's really quite easy to drive. I write Jenkins shell scripts all the time to build xcode projects to specific configurations.
Yeah, I played around with xcodebuild a bit, and it does its job. I'm disappointed with scarcity in online documentation, practical tutorials, tips. etc., of the tool unlike make, however. I suppose people just use xcode to build a project, which is fine as far as it goes, but I'd like to know how things are actually built. Thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.