I have an static Objective-C++ library basic.a, with a function BasicFunction()
. Static Objective-C++ libraries foo.a and bar.a depend on basic.a and have functions Foo()
and Bar()
that call BasicFunction()
.
Here's the tricky part: When I make a project that links in foo.a and bar.a, each built at a different time, I want Foo()
to call the version of BasicFunction()
that was there when it was built, and Bar()
to call the version of BasicFunction()
that was there when it was built. (This is so that newer libraries will not link in an old BasicFunction()
that is missing bug fixes.)
What's happening now is that Foo()
and Bar()
both call the same version of BasicFunction()
, the one that is in whichever of the two foo.a and bar.a that is linked first in the project. Changing symbol visibility does not seem to work because if BasicFunction()
is hidden, it's hidden in basic.a and can't be seen by foo.a or bar.a.
If there is no good way to make the libraries call different versions of BasicFunction()
, how can I at least detect the problem? I've tried a sentinel class that looks to make sure it only gets initialized once, but the linker seems to optimize the two sentinels in different builds of basic.a into just one, again from whichever library that is linked first.
Well, it's unlikely anyone else will have this particular problem, but the solution was to have an Objective-C sentinel class called from a plain C function, both with unique names per build, called by each library. The sentinel class ensures there is only one instance with its name at runtime.