Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Objective-C on Linux (GNUstep)

Install the GCC Objective-C compiler and GNUstep, then compile a Hello World program.

How-To Guides1 min read8 steps5 screenshots

Install the packages

sudo apt-get install gobjc gnustep gnustep-devel -y
Installing gobjc and GNUstep
  • gobjc is the Objective-C front end of GCC.
  • gnustep and gnustep-devel give you the Foundation library and tools.

Create a test program

Create a file hello.m:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog (@"hello world");
    [pool drain];
    return 0;
}
The hello.m file in nano

Load the GNUstep settings

. /usr/share/GNUstep/Makefiles/GNUstep.sh
Sourcing GNUstep.sh

Compile

gcc hello.m -o hello `gnustep-config --objc-flags` -lgnustep-base -lobjc
Compiling the program

The part in backticks adds the compiler flags of GNUstep. -lgnustep-base and -lobjc link the libraries.

Run

./hello
Running the program

You see a line with a time stamp and "hello world".

Features of Objective-C

  1. Object-oriented programming on top of C.
  2. Dynamic typing and binding.
  3. Compatible with C. You can mix C code in.
  4. A messaging system. Objects talk by sending messages.
  5. Automatic reference counting (ARC) in modern compilers.
  6. Frameworks. Foundation and others.
  7. A dynamic runtime.
  8. Protocols (like interfaces).

Quick recap

  • sudo apt-get install gobjc gnustep gnustep-devel.
  • Source GNUstep.sh and compile with the gnustep-config flags.
  • Run ./hello.