So I have nested Static Libraries several times in the past but never quite like this and its causing a bit of an issue.
For now lets assume I have 3 static libraries, A, B, and C. And one project that uses them as follows.
A is a base library composed of commonly used Custom Views, Data structures, and Categories. B is a library linked with A that contains view controllers shared among several projects. C is another library linked with A that contains view controllers shared among several projects.
This particular project uses code from B and C. So the structure looks like this:
A
/ \
B C
\ /
Project
And since the way Xcode links static libraries basically merges them, B and C both have all of A’s symbols. So I’m getting the duplicate symbols linker error. How do I go about dealing with this? Do I need to weak link something? Or is there a particular flag I’m missing? Do I need to set up some type of dependency other thank linking binaries?
I’ve googled and search here and found lots of good information but nothing I’ve been able to twist into this particular situation.
Update on Thoughts
So let me ask this as it seems to be a possible solution after reading that Static Libraries while capable of being merged really shouldn’t be.
Rather than having 3 independent Static Libraries should I put them all in one project and merely have multiple static library targets? Not even using Target Dependencies, just A, AB, and AC, and ABC targets that include the proper files and headers for their target? This will no doubt be rather complicated for build settings and could make source distribution a bit complex, but it would solve my current problem and possible be the better way to handle things. Whatcha think?
It looks like you are not creating static libraries
BandCcorrectly as you are including object files from static libraryA. This is incorrect. Instead makeA,BandCcontain only their own classes’s object files and bring them all together in the final link of theProjectbinary.You will have to allow
Bto seeA‘s header files in order to compile correctly.You will have to allow
Cto seeA‘s header files in order to compile correctly.You will have to allow
Projectto seeA‘s,B‘s andC‘s header files in order to compile correctly as well asA‘s,B‘s andC‘s library (.a) files in order to link correctly.I think that an Xcode Workspace will take care of all of the header/library search path settings for you, once you set-up the project dependencies correctly, but I could be wrong about that and you might have to set those paths up yourself.