I’m trying to build an iOS library/framework, which for the sake of simplicity we’ll say exposes some class A to projects using it. Now the problem is that class A depends upon class B, which is not meant to be exposed (or even included as a symbol) in the build output for the library. This causes problems because there is another library with class C in it that also happens to rely on class B.
What happens is that if I attempt to include both libraries in a project, the linker complains about having multiple definitions of class B.
What is the best way to work around this issue? Is it possible to set class B to be weakly linked when building the two libraries (or at least one of the two libraries), and if so, how?
Or should class B be extracted into its own library/framework and the two libraries modified to reference that instead of including class B as a source file?
I think the best way is to make multiple targets in your project. The easiest way to do this is to click on your project file in the file list on the left side of XCode, right click on the object under “TARGETS” in the middle pane and select Duplicate. Then you can include A and C in one target, and B and C in another. You can compile them separately, and its basically like having two projects except they share common files. Does this sound like what you want?
EDIT On second thought, it doesn’t sound like it. Your problem is happening when you compile to a library, and then link another project to it, right?
It doesn’t seem like there is a way to have weakly linked objects inside of a compiled library. You will probably be better off splitting them into separate libraries (which is sort of what happened in the scenario described at the bottom of this page)