views:

21

answers:

1

When compiling Objective-C from the command line (gcc), what are some good flags to use? Many of the standard C flags (-Wall, -ansi, etc) don't play well with Objective-C.

I currently just use -lobjc and -frameworkwith various frameworks.

A: 

Many of the standard C flags (-Wall, -ansi, etc) don't play well with Objective-C

-Wall works perfectly fine with Objective-C.

The thing to do is build an Objective-C file with Xcode and have a look at the build transcript. I've just done that and here are some highlights:

-x objective-c I guess that means "compile as Objective-C", probably important

-arch x86_64 build for a particular CPU architecture

-std=gnu99 build for C99 + GNU extensions (actually surprised me, I thought Xcode used -std=c99).

-isysroot .... specifies the location of the SDK.

-mmacosx-version-min=10.6 I am compiling for 10.6 and up

-fobjc-gc-only this file was intended to be used with garbage collection and won't work without it, so I compile for GC only.

-Wall the obvious.

If you are compiling from the command line, it's probably a good idea to set the option to treat warnings as errors. I don't from within Xcode because the build results window remembers the uncleared warnings from previous builds.

JeremyP