1

I just created a new cocoa project on Xcode 4.3.3. The preprocessor macros for the Apple LLVM compiler 3.1 settings have a DEBUG=1 $(inherited) value assigned. I removed it and add it again, and now I'm getting an error when compiling :

clang: error: no such file or directory: 'DEBUG=1'

I search for the value on the project settings and I saw that the value is also defined in "Other warning flags"

My questions are:

  1. What is the difference between just having DEBUG vs DEBUG=1?
  2. What does $(inherited) do?
  3. What is it also doing on the other warning flags?
Jason Coco
  • 77,985
  • 20
  • 184
  • 180
the Reverend
  • 12,305
  • 10
  • 66
  • 121
  • 1
    Please be careful when selecting tags. You accidentally created two new tags through typos. – Charles Jul 06 '12 at 23:31
  • Sorry about that, I thought I was selecting them from the auto-complete list. – the Reverend Jul 07 '12 at 00:44
  • Strictly peaking `DEBUG=1` is not standard (though I define it for debug builds). The important one is `NDEBUG=1` for release builds. Its required by Posix to get rid of asserts (which call abort()). Asserts are debug diagnostics that are usually abused. When using Cocoa/CocoaTouch, you will also want to define `NS_BLOCK_ASSERTIONS=1 ` for release builds, too. – jww Nov 12 '12 at 06:31
  • `$(inherited)` means a setting will be inherited from, for example, Project to Target (the Project is the parent, and the Target is the child). It does not mean "child projects" will inherit from "parent projects" in a workspace. That is, `$(inherited)` is not shared among projects. See http://stackoverflow.com/questions/13327744/xcode-4-project-does-not-honor-inherited-build-setting-in-workspace. – jww Nov 12 '12 at 06:36

1 Answers1

1

First, if you're getting a compilation error, then you most likely put the macro back in the incorrect place in the project settings. Please ensure you've put it into the Debug configuration branch of the Preprocessor Macros item under the Apple LLVM compiler x.x - Preprocessing section.

For your other questions:

  1. The first version just defines the macro DEBUG so it's essentially empty. You can test for whether it exists or does not exist, but not much. The second sets it to 1 so that the preprocessor can actually do comparisons like #if DEBUG && SHOULD_DIE_ON_ERROR where you might abort if the application comes across some validation error, but only if SHOULD_DIE_ON_ERROR is set and 1 and you're running in debug mode.
  2. The $(inherited) just brings in other macros you're inheriting from further up the chain. So if your project defines some items and your target defines some more, the target gets the project's settings as well without having to re-define them.
  3. It shouldn't be effecting the warning flags at all. If anything, it determines code paths in header files you include (like the cocoa frameworks) which may use different implementations for things or may add debugging information to data structures, or whatever.
Jason Coco
  • 77,985
  • 20
  • 184
  • 180