1/31/12

Compile Objective C 2.0 (objc 2) on Linux

If you have gcc >4.6 (type 'gcc --version' to check your version), you can use gcc, otherwise use clang(llvm).

On Fedora, install dependencies:
yum install gcc-objc libobjc gnustep-base-devel gnustep-gui-devel
If you want to use llvm, do a "yum install clang"

To compile:
gcc `gnustep-config --objc-flags` `gnustep-config --objc-libs` -lgnustep-base helloworld.m -o helloworld
You have to use clang instead of gcc if you want to use blocks and you have to add '-fblocks' flag.

@property @synthesize works. Blocks also work.

On Ubuntu, install dependencies:
sudo apt-get install gobjc libobjc2 lib32objc2 libgnustep gnustep-base gnustep-devel clang
sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.4/include/objc/ /usr/local/include/objc
To compile:
clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` -lgnustep-base helloworld.m -o helloworld
On my machine (running Ubuntu 10.04), because gcc version is 4.4, I have to use clang. I also couldn't get blocks to work.

Not all language features are possible on linux, for example @autoreleasepool {} works on neither Fedora nor Ubuntu.

1 comment:

Anonymous said...

Thanks, this is exactly what I was looking for. Thanks for sharing!