Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

ios4 - How do you get implicit dependencies to work with workspaces in Xcode 4?

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.

Build Failed

You can see how the build fails because it cannot find the dependencies.

Build Errors

To resolve these issues I added manually linked the Library1 and Library2 projects.

Manual Linking

I also had to add the path to these projects as Header Search Paths.

Manually Reference Headers

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:

  • How are "implicit dependencies" supposed to work in Xcode 4 with workspaces?
  • Why can't the code in Libary1 and Library2 be found automatically in PrimaryApp?
  • Are additional changes required to make dependencies work in a workspace?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Create a new Workspace in Xcode.
  2. Add a new project to the workspace for your static library. You can also add an existing project, I found this to work too.
  3. Test that the library builds as expected.
  4. 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.
  5. At this stage I am going to assume that your source code already contains imports of headers from the static library.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...