6

I am working on a static library, called Silicon, that I use for all of my iOS apps.

Because I don't want to create one massive static library that could become hard to maintain I create lots of smaller static libraries that I attach as submodules.

As of the time of this writing the dependency tree for Silicon is as follows:

Silicon
|
|==> FDKeychain
|==> FDDataClient
        |
        |=> FDRequestClient
                |
                |=> FDFoundationKit
|==> FDSQLiteDatabase
        |
        |=> FDFoundationKit

As you can see both FDRequestClient and FDSQLiteDatabase have FDFoundationKit as a common static library.

What seems to happen is that when a project using Silicon is built it builds all of Silicon's target dependencies to the projects build directory. The same thing happens for FDDataClient and FDSQLiteDatabase. So at some point FDFoundationKit from FDRequestClient is built and copied to the build directory as well as FDFoundationKit from FDSQLiteDatabase. Whichever one is built last just overwrites the previous one.

Just by sheer luck FDFoundationKit hasn't been changing in any serious ways such that FDRequestClient and FDSQLiteDatabase can't always be using the same version but I can't guarantee it will be like this forever.

I am trying to figure out if there is a way for Silicon to specify which version of FDFoundationKit to use so it can be Silicon's responsibility to ensure that the the version used will work for both FDRequestClient, FDSQLiteDatabase and any other dependencies I add in the future.

I know CocoaPods attempts to solve this problem but I do not want to make someone have to setup all of that just to get my library working. If I could just find someway of having Silicon define which version of FDFoundationKit to use everything would work perfectly.

Reid Main
  • 3,394
  • 3
  • 25
  • 42
  • You don't want to use CocoasPods because you "do not want to make someone have to setup all of that just to get my library working". I'm pretty sure that most suggestion that other user will make here will take you more time to setup and manage that if you do the one-time setup of a private CocoaPods. – Emilie May 21 '14 at 14:57
  • 2
    But for users of Silicon there will be no setup. They just link the static library and everything works. If I switch to CocoaPods then everyone who wants to use this library will need to have it. I'm trying to do the legwork with this library to ensure that if you link it it will build correctly. – Reid Main May 21 '14 at 14:59

2 Answers2

0

You could (as we do) place all of your libraries into frameworks, as frameworks support versioning. Frameworks are just a directory tree configured in a common manner. Xcode does not directly support the creation of frameworks, so you have to create them in a script, typically as the last of your build phases. An example (thanks to jverkoey) can be found at IOS- framework

Within a framework you may store all versions of each static library within the

myLibrary.framework->Versions->n.n folders. 

The myLibary.framework->Versions->Current is a link to the folder of the latest version.

Since you are using static libraries, Silicon itself cannot specify the versions (that would require dynamic libraries), however the build, linker or environment flags used for the building of Silicon certainly can.

In this manner, by default, Apps will always use the latest version of the library, but the actual version linked may be easily overridden by linker flags when building. Also, all users will simply include the Silicon framework in their project in the same manner as any other framework, so it's very simple for developers.

Gowri
  • 1,832
  • 3
  • 29
  • 53
Some Developer
  • 267
  • 2
  • 10
  • 2
    I think, the problem is not versioning, but duplicate symbols when the same symbol is visible in more than one static library (archive), no matter how you structure the archives. Dynamic link libraries do not have this problem. – CouchDeveloper Oct 17 '14 at 05:23
  • The OP only mentions versioning as the problem. – Some Developer Oct 20 '14 at 15:34
  • I actually have switched Silicon over from static libraries to frameworks and @CouchDeveloper is right in that I do want to ensure the there are no duplicate symbols. My ideal scenario with any of my open source projects is that I can make one dependent on the other but if someone used two of my frameworks that both had the same dependency they aren't going to get a collision. – Reid Main Oct 28 '14 at 04:47
0

There looks to be only two answers to this problem:

1) Use a dependency manager like CocoaPods or Carthage.

2) Any static libraries or frameworks you release should not have any target dependencies. They should link against any dependencies you have and it is the responsibility of person integrating your library to also integrated the required dependencies.

Reid Main
  • 3,394
  • 3
  • 25
  • 42