I have just spent the best part of two days building and rebuilding our project, struggling with just this very issue. Whilst I now have a project that builds and links correctly AND has working codesense I am not 100% happy with one of the steps as it seems to be a bit of a hack and certainly doesn’t fit my concept of “Automatic implicit dependencies”.
FWIW here are the steps I took:
- Create a new Workspace in Xcode.
- Add a new project to the workspace for your static library. You can also add an existing project, I found this to work too.
- Test that the library builds as expected.
- Add a new project to the workspace for your main project. Again I managed to add an existing one, but importantly it did not have any build settings already that linked to the library. If you add a new project its fairly easy to just add existing source files to it. My particular situation was complicated by a very large pre-existing SVN repository that I did not want to restructure.
- At this stage I am going to assume that your source code already contains imports of headers from the static library.
- In the build phases for the main project, expand the “link binary with libraries” section and click the + symbol. Select the target from your static library project.
- If you want at this stage you can build the main project to confirm that it fails as shown in the OP screen shots with “No such file…” errors for the header imports.
- Now this is the bit I don’t really like. In your main project create a new group and call it Dependent Headers or whatever. Now in the project navigator drag any used headers from your static project to this new group. In the options pop up I just left it as the default settings.
- You may also need to link your main project with any dependent libraries used by your static library. For example my static library makes use of libxml2 and CFNetwork and even though my main project does not use them directly I had compile errors if I did not add them to the “link binary with libraries” build phase.
- Your main project should now (hopefully) build.
I really don’t like steps 8 and 9. This really feels like XCode is not doing what it is advertised to do. However if and when it gets fixed at least these steps are fairly easy to back out so that it works correctly.
I think “implicit dependencies” should work without needing to go past step 6, maybe even step 5 but that might be a little bit too automagical for a lot of people’s taste.