iPhone -- nest libraries in a project without linker errors?
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 Librar开发者_如何转开发yA 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.
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.
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
精彩评论