Linking static libraries sharing a static library

Currently, I have one Xcode project for a very large code base, I will name it Project X , which I divide into a bunch of subprojects ( Projects A, B, C ).

So far, each of these projects compiles on its own, just fine. They all create static libraries. Project B and Project C depend on the static library Project A created for the build.

I have another xcode project, Project Z , which requires the static libraries created by Projects B and C. This is the problem. When Project Z enters the linker phase, everything is fine - the characters in libs are duplicated for Projects B and C for the code originally associated with it in Project A

I'm new to the world of static libraries, and I'm not sure how to move forward with Project Z , or how to change other projects so that they link to the same Project A lib. I have a feeling that this is impossible. What are my options?

Edit:

I must clarify that Project B and Project C need to be integrated into separate static libraries, because some clients only need one or the other.

In addition, I have this dilemma on both OSX and iOS platforms.

I understand that I could solve this problem on OSX by building projects as dynamic libraries. However, I would rather not do this, and it still leaves me the same problem on iOS.

+12
design linker xcode static-libraries
Jul 31 '12 at 23:14
source share
2 answers

Static libraries should never include other static libraries (or third-party code in general). A static library is just a collection of .o files glued together. Therefore, if you have several copies of the same information, it will explode.

Each static library should only have its own code. The final application is responsible for consolidating all the required libraries (including the libraries required by the libraries). Thus, there is one copy of each related item.

+16
Aug 01 '12 at 19:08
source share

This seems like a problem like CoacoaPods was created to solve. If you define containers for each of these projects, then Z should be able to define and link all its dependencies throughout the chain without introducing duplicate characters.

+2
Aug 01 '12 at 17:22
source share



All Articles