3

This is driving me crazy.

I have library A which in turn includes library B. The nested pair of libraries are used in 5 different projects. I want to have the source for A and B in a single place and link all 5 projects to them.

No matter what I do, I get one of two kinds of errors:

1) A class of library B colliding with itself. The linker sees said class in library A and also in library B.

2) Some classes missing, because the linker can't find them.

I should mention that library A includes categories. I am dealing with the category bug by having a dummy class in each category file and using the ObjC linker flag in the outer project.

Here is the setup I am trying to use. As described below, I get the duplicate symbols.

I have directories Documents/LibraryA, Documents/LibraryA/LibraryB, and Documents/Project1 through Documents/Project5.

The directory Documents/Project1 has a symlink LibraryA which points to ../LibraryA. The same holds true for projects 2 through 5.

Header search paths in the containing project are ./LibraryA ./LibraryA/Classes/** and ./LibraryA/LibraryB/**

Header search paths in LibraryA are ./LibraryB/**

Library search paths are always empty.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323

2 Answers2

1

as complexity/sharing increases, you realize the way to link statically (while maintaining your sanity) when libraries are heavily reused is to save the link process (of the publicly reused images) for the final executable's link stage.

therefore, a static library links only to private internal libraries (not typically found in smaller codebases) while the final executable links to every publicly visible library (and their dependencies).

this will of course expose dependencies when linking the final executable.

if the libraries may be grouped, you may also merge them into one library to create a meta library, assuming you ensure the meta library's sub-libraries are never linked in other stages of all executables it links to.

justin
  • 104,054
  • 14
  • 179
  • 226
  • How can you have private internal libraries on the iPhone? I thought the main project always had to link to every library, even sub-libraries. – William Jockusch Aug 22 '11 at 14:49
  • 1
    you accomplish it by linking a static library target to another static library target. in that case, the libraries are merged. this usually occurs only with large or complex libraries and/or codebases, but can be useful in other cases. i'll typically do this when libraries become very large or significant portions are best divided for organizational purposes. in addition to smaller, more manageable projects, you can reduce link and build times. – justin Aug 22 '11 at 19:47
  • 1
    Woah, can I upvote this a million times? I was always under the impression that the top-level projects had to link directly to the sub-libraries, by including them in the "link binary with libraries" build step. Apparently this is not the case. I don't know if this is an improvement by Apple, or if I had been missing the boat all along. In either case, a million thanks. – William Jockusch Aug 23 '11 at 03:08
  • you're welcome. it has been possible to link like this for years (not sure how many). that's how linking statically works -- it's just not too common to see this strategy in Xcode projects or obvious from the ide that static images may be merged when linked. as you have probably figured out by now, it helps to define a common set of build settings for collections of static libraries, so you can keep all the build and link settings identical. in the end, it's quite easy to maintain complex dependencies using static libs -- far simpler than dylibs in some regards. cheers. – justin Aug 23 '11 at 04:30
  • @justin could you please provide an example of what you mean? if you have a github repo that would be awesome. or go here and answer my question and i'll give you 500 points bounty: http://stackoverflow.com/questions/13264847/xcode-with-ios-creating-a-library-in-a-way-that-is-easy-to-run-in-debug-mode – jpswain Nov 15 '12 at 08:13
0

Have you tried to setup all these projects according to XCode workspace?
check this doc
http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Workspace.html#//apple_ref/doc/uid/TP40009328-CH7-DontLinkElementID_1

Aruna
  • 701
  • 10
  • 26