将不同版本的静态库中的符号分开
我有一个静态 Objective-C++ 库 basic.a,带有函数 BasicFunction()
。静态 Objective-C++ 库 foo.a 和 bar.a 依赖于 basic.a 并具有函数 Foo()
和 Bar()
调用 BasicFunction()
。
这是棘手的部分:当我创建一个链接 foo.a 和 bar.a 的项目时,每个项目都在不同的时间构建,我想要 Foo()
调用构建时的 BasicFunction()
版本,Bar()
调用 BasicFunction()< 版本/code> 当时就在那里建造的。 (这样新的库就不会链接到缺少错误修复的旧
BasicFunction()
中。)
现在发生的情况是 Foo()
和 Bar ()
都调用相同版本的 BasicFunction()
,即 foo.a 和 bar.a< 中的任意一个版本。 /strong> 中第一个链接的 项目。更改符号可见性似乎不起作用,因为如果隐藏 BasicFunction()
,它就会隐藏在 basic.a 中,并且 foo.a< 无法看到/strong> 或 bar.a。
如果没有好的方法让库调用不同版本的 BasicFunction()
,我怎样才能至少检测到问题呢?我尝试过一个哨兵类,它看起来确保它只初始化一次,但链接器似乎将不同版本的 basic.a 中的两个哨兵优化为一个,再次来自哪个库首先链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,其他人不太可能遇到这个特殊问题,但解决方案是从普通 C 函数调用 Objective-C 哨兵类,每个构建都有唯一的名称,由每个库调用。哨兵类确保在运行时只有一个具有其名称的实例。
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.