On Nov 20, 2006, at 9:38 PM, Andrew Cunningham wrote: I have come back to XCode 2.4.1 after a long hiatus, and must be missing something very obvious about targets and include files....
Assume I have a project with two targets "Target 1" and "Target 2"
"Target 1" has an include file "A.h" file. This file is in the XCode project - 'Get Info' on this include file shows it as a member of "Target 1" ONLY
"Target 2" has a source file, B.cpp. B.cpp has a '#include "A.h"', but it is meant to be a different "A.h" pointed to by the targets "-I" directive. B.cpp is a member of "Target 2" ONLY. "Target 2"'s include file paths specifically do not reference the location of the "A.h" file that is in "Target 1".
The problem is that when compiling B.cpp ( part of Target 2), XCode is including the "A.h" (from "Target 1"). Presumably header files added to the project implicitly becomes an include file for all targets , despite the target membership of the header file.
I find this behavior quite strange. I am clearly indicating to XCode that the "A.h" in the project belongs only to "Target 1". I think it's really nice in XCode that when you add header files to XCode, they become implicitly part of the "include" path, but there should be control of this at the target level.
Target membership has nothing to do with where #include files are found. In most cases, you don't even want your #include files to be target members, lest they get acted on (compiled, copied into the Headers directory, copied into the Resources directory, etc.) during a build.
In CodeWarrior, if you recall, headers were not even project members, much less target members. The main reason they're usually target members in Xcode is that the SCM support is integrated at the project level, so to have your headers under SCM control they need to be in the project.
What determines header-finding in Xcode, just like in CodeWarrior, is the Header Search Path. If you have two different headers with the same name in different targets, the Header Search Paths in those targets need to be set differently, so that the compiler finds the right one for the target first. You're right, Xcode does set this for you automatically—but it can't really intuit that you mean a different A.h in target 2 than in target 1, so it's up to you to set target 2's Header Search Paths differently, so it finds Headers/Target 2/A.h and not Headers/Target 1/A.h.
What I'd do is remove A.h from both targets, and then make sure that Target 1 has a Header Search Path to Headers/Target 1 and Target 2 has a Header Search Path to Headers/Target 2.
Chris |