I am new to building static libraries and would like to create 2(+) libraries each of which has some unique code and some shared code. My intention is that other projects will link one or more of these static libraries.
Util.h/m <-- Shared
ImplOne.h/m <-- Unique to 'ImplOne'
ImplTwo.h/m <-- Unique to 'ImplTwo'
I am using XCode and generating the libraries by building Util.m and ImplOne.m in one case, and Util.m and ImplTwo.m in the other.
Of course the issue is that I now cannot use these libraries together because they will have duplicate symbols. What is a better architecture for this situation?
I think the cleanest alternative would be to make a separate library for the shared
Utils.h/m. The drawbacks are that your users would need to linkutilsalong withimploneand/orimpltwo, and that in order to linkimpooneandimpltwotogether both libraries need to be compiled with the same version ofutils. In return, the source of the libraries would stay nice and clean.An alternative would be to use macros to alter function and variable names in the
utilsto avoid linker errors. The most important consequence of this is code duplication: bothimploneandimpltwowould link identical pieces of code under different names. The other one is readability: it would suffer tremendously, because each reference to a function inutilswould need to be wrapped in a macro. This makes the second approach dirty, so I would definitely recommend makingutilsa separate library.