views:

981

answers:

4

On OS X, does Objective-C compile to native code or byte-code?

Can Objective-C programs be compiled on Linux?

+1  A: 

Objective-C is a variant of C. It compiles to native code.

Andrew Medico
+2  A: 

Yes, Objective-C compiles to machine code.

Objective-C compilers exist for Linux, but Cocoa is an OS X-only technology. I've heard of an open replacement called GNUstep, but don't know much about it.

Bill Williams
I used to work as a GNUstep developer - still have the SVN commit flag but haven't actually done so in a while. It's a nice system and provides a good amount of source compatibility with Cocoa, but you'd be misguided if you thought that you could just take an arbitrary Mac app and type 'make'.
Graham Lee
+11  A: 

Objective-C is compiled to native code by either GCC or LLVM. You can compile ObjC programs on Linux (the generic GCC will happily support ObjC, though it uses a different runtime library than either of the Apple ones). For a cross-platform API similar to Cocoa (i.e. derived from Cocoa) which will happily work on Linux and let you port some code between OS X and Linux, check out GNUstep: http://www.gnustep.org

Graham Lee
To clarify, for 'LLVM' read 'GCC using the LLVM back-end'. LLVM on it's own is not a compiler but a back-end machine-code generator.
@Mike good clarification, thanks.
Graham Lee
Apple is working on clang, a front-end to LLVM; GCC is not used at all in this path. It's not ready for production usage yet, though.
ephemient
Also, Cocoa would be more accurately described as being derived from GNUStep (OpenStep) than the other way around.
Marcin
@marcin Cocoa is a marketing term for Apple's OpenStep implementation[*], and GNUstep is derived from OpenStep…[*] a non-compliant implementation as it lacks the DPS functions ;-)
Graham Lee
Cocoa is in no way derived from GNUstep.
Chris Hanson
+4  A: 

It's native.

There is GNUstep which an Open Source implementation of the NeXT OpenStep specification written in Objective-C. Their implementation of the Cocoa API is not a direct match so a direct compilation without porting is not possible.

fhe