I want to manage projects in workspaces using Xcode 4 with Cocoa Touch Static Library projects which contain shared code that I could reference from other projects. According to WWDC 2010 videos and the Xcode 4 documentation there is a feature for "implicit dependencies" for workspaces in Xcode 4. I have been trying to make it work and I am not having much success.
Sample Workspace: DependenciesInXcode4.zip
You can see the very basic sample project has 2 static library projects which I named Library1 and Library2. I then have a single class in each project which I reference from the iPhone project called PrimaryApp. I get support from Code Sense when adding the import statement but the build fails.
You can see how the build fails because it cannot find the dependencies.
To resolve these issues I added manually linked the Library1 and Library2 projects.
I also had to add the path to these projects as Header Search Paths.
Now when I build both of the dependency libraries and then run PrimaryApp in the iPhone Simulator it builds successfully and runs. I have found that it does not always ensure that the dependency projects are built when necessary and this is clearly a manual process. This is not what I consider "implicit dependencies" as the Xcode videos and documentation imply that it should work. I have been looking for more concrete examples but so far I have had no luck. Even here on Stackoverflow I do not see a satisfactory answer yet.
It appears that developers are falling back to old techniques and not truly using the new "implicit dependencies" features.
I'd appreciate some help with understanding how to get "implicit dependencies" to work with workspaces in Xcode 4.
Here are my questions:
Workspaces Extend the Scope of Your Workflow Although a project can contain references to other projects, working on interrelated projects in Xcode 3 is complicated; most workflows are confined to a single project.
An Xcode project is a repository for all the files, resources, and information required to build one or more software products. A project contains all the elements used to build your products and maintains the relationships between those elements.
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:
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.
This really does seem to be a bug in Xcode's handling of implicit dependencies during the build process.
In a workspace with two projects, I was able to have Project A see classes in Project B and successfully build by copying the .h header files for Project B's classes into Project A's directory. NOTE: I did not add them to Project A in Xcode I just put them in Project A's directory in the Finder.
This is a much easier solution than I've seen outlined elsewhere, as it requires no changes to workspace schemes or to the build settings of either project. With the .h files in Project A's directory, Xcode was able to automagically find and resolve all of Project A's implicit dependencies on Project B.
Unfortunately you cannot put the .h files in their own subdirectory called "XcodeBugWorkaroundHeaderFiles". They have to be in a directory that the project is already reading .h files out of. Also, Aliases won't work, but Symbolic Links will, so by using SymLinks you don't have to worry about out-of-date copies.
With all of this said, I'm not sure that having "stealth" .h files that the build build will fail without is a good idea, though. Until the bug is fixed in Xcode, it is probably best just to add them to the project so you can see them in Xcode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With