[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to compile a .m
From: |
David Chisnall |
Subject: |
Re: how to compile a .m |
Date: |
Wed, 14 Oct 2009 09:28:13 +0100 |
A couple of other people have already mentioned GNUstep Make. For
short programs, gnustep-config is also an option. You can compile a
simple Objective-C program like this:
gcc `gnustep-config --objc-flags --base-libs` hello.m
This will generate an a.out file linked against GNUstep Base
(Foundation). Substitute --gui-libs if you want to link AppKit (but,
generally, if you are linking against AppKit you will want to make a
bundle and then it's much easier to use GNUstep Make). For both, you
will need to source the GNUstep.sh file first, I believe (I'm not 100%
sure if gnustep-config needs this).
On 14 Oct 2009, at 00:30, Jean-Loïc Mauduy wrote:
#import <stdio.h>
This is wrong. A few Objective-C tutorials make this mistake, and
tell you to just use #import instead of #include in Objective-C
programs, but this is terrible advice. #include is a trivial
preprocessor directive that just inserts the contents of the specified
file at this point. #import is a bit more clever, and ensures that
the file is only ever inserted once.
Objective-C headers are, generally, designed to be used with #import.
A lot of C (and C++) headers, however, are not. They will protect
themselves from multiple inclusion with macros and may be designed to
work differently if included more than once in a compilation unit. If
you get into the habit of using #import with C headers, then you are
going to end up with something breaking eventually, and you are going
to be very confused about why. Only use #import with Objective-C
headers; stick with #include for C headers. This also provides a clue
to people reading your code about what kind of header you are including.
David
-- Sent from my Apple II