Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: [Objective-C] HOWTO: Compiling Objective-C with gcc

  1. #1
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    [Objective-C] HOWTO: Compiling Objective-C with gcc

    Hi there!
    I'm here looking a bit into Objective-C and I'm impressed. It's a really nice language (just "C with Classes" not C++ bloat) but I won't go into that here.

    But I had real troubles to get the sources compiled with gcc under Debian (so Ubuntu is surely the same) and after a lot of research, I could. Here's a little how-to for anyone interested.

    1. Install the GNU Objective-C Runtime.
    Code:
    sudo apt-get install gobjc
    Despite what some webpages imply, you don't need GNUStep (the GNU clone of Apple NeXTStep).

    2. Write some source. Here's a very small example.
    Code:
    // hello.m
    #import <objc/Object.h>
    #import <stdio.h>
    
    @interface Number: Object
    {
    @public
        int number;
        
    }
    
    - (void)printNum;
    
    @end
    
    @implementation Number: Object
    
    
    - (void)printNum
    {
        printf("%d\n", number);
    }
    
    @end
    
    int main(void)
    {
        Number *myNumber = [Number new]; // equal to [[Number alloc] init]
    
        myNumber->number = 6;
    
        [myNumber printNum];
    
        return 0;
    }
    As you see, there are some differences with Apple Objective-C. The base object class is called Object, not NSObject. The Object class's interface is at objc/Object.h, as you see it #import'ed.

    3. Compile:
    Code:
    gcc -o hello hello.m -Wall -lobjc
    -o and -Wall are optional, as you surely know if you have used gcc or g++ before for C or C++, respectively. The key argument is -lobjc. For some weird reason, you have to manually link to the GNU Objective-C Runtime, otherwise, you're lost.

    If you happen to be using gcc in Mac OS X, then you have to also pass -fgnu-runtime to avoid the Apple NeXTStep Runtime.

    @end

  2. #2
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    I have been thinking of investigating objc too.. what are you using to learn from?
    LambdaGrok. | #ubuntu-programming on FreeNode

  3. #3
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    Quote Originally Posted by CptPicard View Post
    I have been thinking of investigating objc too.. what are you using to learn from?
    Objective-C is just a couple of Smalltalk-like extensions over C, so you just learn those extensions and the rest is pure old C. It's a really nice OOP low-level language.

    I use Apple's official documentation. But take in account the #import <objc/Object.h> and the Object vs. NSObject issues I described above.

    http://developer.apple.com/documenta...001163-CH1-SW2

    This is also very good:
    http://objc.toodarkpark.net/

  4. #4
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    Too bad that at least according to the "computer language benchmarks game" ObjC is about comparable to Java in speed, and at least for me the only reason to move down the ladder in the C-direction is an increase of speed. Having some higher-level features thrown in on top of C would be really nice though (especially so that it does not turn into C++ )
    LambdaGrok. | #ubuntu-programming on FreeNode

  5. #5
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    It really is a nice language, but unfortunately it needs so much work to really be useful outside of OSX (in terms of libraries). I think the GTK binding project has halted as well. Not sure what other libraries are out there at the moment, it's been a while since I've looked.

  6. #6
    Join Date
    Jan 2006
    Beans
    1,234
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    It would be really great to see someone compare objc to vala
    Last edited by cb951303; February 8th, 2009 at 09:56 PM.

  7. #7
    Join Date
    Jul 2008
    Beans
    9
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    I'm a CS student in my last week of an intro C class... my first marked exploration in programming was in Python, Ruby, etc. and a little C++. I'm addicted to OOP, but I love how close C is to the hardware, and indeed, how much more real it feels. The solution might be C++, but I find the code to be quite ugly and too complicated. I've found objc to be the natural solution... I really hope to see more support for it, especially on the GNU/Linux platform.

  8. #8
    Join Date
    Jul 2008
    Beans
    9
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    thanks for the HOWTO, by the way!

  9. #9
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    Quote Originally Posted by cpatton90 View Post
    I'm a CS student in my last week of an intro C class... my first marked exploration in programming was in Python, Ruby, etc. and a little C++. I'm addicted to OOP, but I love how close C is to the hardware, and indeed, how much more real it feels. The solution might be C++, but I find the code to be quite ugly and too complicated. I've found objc to be the natural solution... I really hope to see more support for it, especially on the GNU/Linux platform.
    The support is there, the issue are the libraries. We're stuck on a NeXTStep/GNUStep (or its fork SideStep) mindset where Objective-C development means to necessarily use those frameworks, which is totally untrue.

    That's why some people (including me) are working on a joint effort to create non-Step Free Software libraries for basic core classes. Look at COList at my sig. Look at the sister projects by the Core Objectives team too.

  10. #10
    Join Date
    Nov 2009
    Beans
    3

    Re: [Objective-C] HOWTO: Compiling Objective-C with gcc

    After compilation you get a hello file of type exec

    to launch it type :
    /.hello

    thanks for the HOW TO nvteighen

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •